<commit_before><?php
namespace PhpFlo;

class ArrayPort extends Port
{
    private $sockets = array();

    public function attach(SocketInterface $socket)
    {
        $this->sockets[] = $socket;
        $this->attachSocket($socket);
    }

    public function detach(SocketInterface $socket)
    {
        $index = array_search($socket, $this->sockets);
        if ($index === false) {
            return;
        }

        $this->emit('detach', array($socket));
        $this->sockets = array_splice($this->sockets, $index, 1);
    }

    public function send($data, $socketId = 0)
    {
        if (!isset($this->sockets[$socketId])) {
            throw new \InvalidArgumentException("No socket {$socketId} connected");
        }

        if ($this->isConnected($socketId)) {
            return $this->sockets[$socketId]->send($data);
        }

        $this->sockets[$socketId]->once('connect', function(SocketInterface $socket) use ($data) {
            $socket->send($data);
        });
        $this->sockets[$socketId]->connect();
    }

    public function connect($socketId = 0)
    {
        if (!isset($this->sockets[$socketId])) {
            throw new \InvalidArgumentException("No socket {$socketId} connected");
        }

        $this->sockets[$socketId]->connect();
    }

    public function disconnect($socketId = 0)
    {
        if (!isset($this->sockets[$socketId])) {
            return;
        }

        $this->sockets[$socketId]->disconnect();
    }

    public function isConnected($socketId = 0)
    {
        if (!isset($this->sockets[$socketId])) {
            return false;
        }

        return $this->sockets[$socketId]->isConnected();
    }
}<commit_msg>ArrayPort: adding isAttached method.<commit_after><?php
namespace PhpFlo;

class ArrayPort extends Port
{
    private $sockets = array();

    public function attach(SocketInterface $socket)
    {
        $this->sockets[] = $socket;
        $this->attachSocket($socket);
    }

    public function detach(SocketInterface $socket)
    {
        $index = array_search($socket, $this->sockets);
        if ($index === false) {
            return;
        }

        $this->emit('detach', array($socket));
        $this->sockets = array_splice($this->sockets, $index, 1);
    }

    public function send($data, $socketId = 0)
    {
        if (!isset($this->sockets[$socketId])) {
            throw new \InvalidArgumentException("No socket {$socketId} connected");
        }

        if ($this->isConnected($socketId)) {
            return $this->sockets[$socketId]->send($data);
        }

        $this->sockets[$socketId]->once('connect', function(SocketInterface $socket) use ($data) {
            $socket->send($data);
        });
        $this->sockets[$socketId]->connect();
    }

    public function connect($socketId = 0)
    {
        if (!isset($this->sockets[$socketId])) {
            throw new \InvalidArgumentException("No socket {$socketId} connected");
        }

        $this->sockets[$socketId]->connect();
    }

    public function disconnect($socketId = 0)
    {
        if (!isset($this->sockets[$socketId])) {
            return;
        }

        $this->sockets[$socketId]->disconnect();
    }

    public function isConnected($socketId = 0)
    {
        if (!isset($this->sockets[$socketId])) {
            return false;
        }

        return $this->sockets[$socketId]->isConnected();
    }

    /**
     * Checks if socket is attached.
     *
     * @param int $socketId
     * @return bool
     */
    public function isAttached($socketId = 0)
    {
        if (!isset($this->sockets[$socketId])) {
            return false;
        }

        return true;
    }
}
{'fraction_non_alphanumeric': 0.15859269282814614, 'fraction_numerical': 0.002976995940460081, 'mean_word_length': 2.256387665198238, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6685276', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1041, 'n_words': 201}