<?php

namespace Puphpet\Domain\PuppetModule;

class Server extends PuppetModuleAbstract implements PuppetModuleInterface
{
    protected $disallowedPackages = ['python-software-properties'];
    protected $server;

    public function __construct($server)
    {
        $this->server = is_array($server) ? $server : array();
    }

    /**
     * Return ready to use server array
     *
     * @return array
     */
    public function getFormatted()
    {
        if (empty($this->server)) {
            return array();
        }

        $this->formatBashAliases()
             ->formatPackages();

        return $this->server;
    }

    /**
     * Submitted .bash_aliases contents
     *
     * @return self
     */
    protected function formatBashAliases()
    {
        $this->server['bashaliases'] = !empty($this->server['bashaliases'])
            ? trim(str_replace("\r\n", "\n", $this->server['bashaliases']))
            : '';

        return $this;
    }

    /**
     * A comma-delimited string of package names
     *
     * @return self
     */
    protected function formatPackages()
    {
        $this->server['packages'] = !empty($this->server['packages'])
            ? explode(',', $this->server['packages'])
            : array();

        foreach ($this->disallowedPackages as $disallowed) {
            unset($this->server['packages'][$disallowed]);
        }

        $this->server['packages'] = $this->quoteArray($this->server['packages']);

        return $this;
    }
}

<?php

namespace Puphpet\Domain\PuppetModule;

class Server extends PuppetModuleAbstract implements PuppetModuleInterface
{
    protected $server;

    public function __construct($server)
    {
        $this->server = is_array($server) ? $server : array();
    }

    /**
     * Return ready to use server array
     *
     * @return array
     */
    public function getFormatted()
    {
        if (empty($this->server)) {
            return array();
        }

        $this->formatBashAliases()
             ->formatPackages();

        return $this->server;
    }

    /**
     * Submitted .bash_aliases contents
     *
     * @return self
     */
    protected function formatBashAliases()
    {
        $this->server['bashaliases'] = !empty($this->server['bashaliases'])
            ? trim(str_replace("\r\n", "\n", $this->server['bashaliases']))
            : '';

        return $this;
    }

    /**
     * A comma-delimited string of package names
     *
     * @return self
     */
    protected function formatPackages()
    {
        $this->server['packages'] = !empty($this->server['packages'])
            ? explode(',', $this->server['packages'])
            : array();

        $key = array_search('python-software-properties', $this->server['packages']);

        // python-software-properties is installed by default, remove to prevent duplicate Puppet function
        if ($key !== FALSE) {
            unset($this->server['packages'][$key]);
        }

        $this->server['packages'] = $this->quoteArray($this->server['packages']);

        return $this;
    }
}

Revert "Unsetting non-existant key does not throw notice/error, so unset without checking"
Revert "Unsetting non-existant key does not throw notice/error, so unset without checking"

This reverts commit 532b3e771755fda3909fc46a02211dfc3317730d.
