<?php

namespace Lawstands\Hermes;

/**
 * Created by BrainMaestro
 * Date: 28/1/2017
 * Time: 2:20 PM
 */
class Channel
{
    /**
     * @var array
     */
    private $receivers = [];

    /**
     * Channel constructor.
     * 
     * @param array $receivers
     */
    public function __construct(array $receivers)
    {
        foreach ($receivers as $receiver) {
            if ($this->isValid($receiver)) {
                $this->receivers[] = $receiver;
            }
        }
    }

    /**
     * Get all receivers.
     *
     * @return array
     */
    public function getReceivers()
    {
        return $this->receivers;
    }

    /**
     * Validate receivers.
     *
     * @param $receiver
     * @return bool
     */
    private function isValid($receiver)
    {
        return file_exists($receiver);
    }
}

<?php

namespace Lawstands\Hermes;

/**
 * Created by BrainMaestro
 * Date: 28/1/2017
 * Time: 2:20 PM
 */
class Channel
{
    /**
     * format: extension => program
     * @var array
     */
    private static $types = [
            'rb' => 'ruby',
            'py' => 'python',
        ];

    /**
     * Validate channels.
     *
     * @param array $channels
     * @return array
     */
    public static function validate(array $channels)
    {
        // create an array of valid channels.
        // the array filter removes the null elements which are
        // the invalid channels.
        return array_filter(array_map(function ($channel) {
            $channel['type'] = self::getType($channel);

            return self::isValid($channel) ? $channel : null;
        }, $channels));
    }

    /**
     * Validate channels.
     *
     * @param $channel
     * @return bool
     */
    private static function isValid($channel)
    {
        return file_exists($channel['path']);
    }

    /**
     * Get a channel's type.
     *
     * @param $channel
     * @return void
     */
    private static function getType($channel)
    {
        if ($channel['type']) {
            return $channel['type'];
        }

        $extension = pathinfo($channel, PATHINFO_EXTENSION);
        // choose type if it was found in the types map
        // or use extension as the type.
        return array_key_exists($extension, self::$types) ? self::$types[$extension] : $extension;
    }
}

Update channel to use static functions
Update channel to use static functions
