<commit_before><?php

namespace Innmind\Neo4j\DBAL;

class DelegateConnection implements ConnectionInterface
{
    protected $connections = [];
    protected $ordering = [];
    protected $activeConnection;

    /**
     * Add a connection
     *
     * @param string $name
     * @param Connection $conn
     *
     * @return DelegateConnection self
     */
    public function addConnection($name, Connection $conn)
    {
        $this->connections[(string) $name] = $conn;
        $this->ordering[] = (string) $name;

        return $this;
    }

    /**
     * Return a specific connection
     *
     * @param string $name
     *
     * @throws InvalidArgumentException If the connection does not exist
     *
     * @return Connection
     */
    public function getConnection($name)
    {
        if (!isset($this->connections[$name])) {
            throw new \InvalidArgumentException(sprintf(
                'Unknown connection named "%s"',
                $name
            ));
        }

        return $this->connections[$name];
    }

    /**
     * Return the first active connection
     *
     * @throws RuntimeExecption If no connection is alive
     *
     * @return Connection
     */
    public function getActiveConnection()
    {
        if ($this->activeConnection) {
            return $this->activeConnection;
        }

        foreach ($this->getConnections() as $conn) {
            if ($conn->isAlive()) {
                return $this->activeConnection = $conn;
            }
        }

        throw new \RuntimeException('No connection alive');
    }

    /**<commit_msg>allow to get dispatcher of the active connection<commit_after><?php

namespace Innmind\Neo4j\DBAL;

class DelegateConnection implements ConnectionInterface
{
    protected $connections = [];
    protected $ordering = [];
    protected $activeConnection;

    /**
     * Add a connection
     *
     * @param string $name
     * @param Connection $conn
     *
     * @return DelegateConnection self
     */
    public function addConnection($name, Connection $conn)
    {
        $this->connections[(string) $name] = $conn;
        $this->ordering[] = (string) $name;

        return $this;
    }

    /**
     * Return a specific connection
     *
     * @param string $name
     *
     * @throws InvalidArgumentException If the connection does not exist
     *
     * @return Connection
     */
    public function getConnection($name)
    {
        if (!isset($this->connections[$name])) {
            throw new \InvalidArgumentException(sprintf(
                'Unknown connection named "%s"',
                $name
            ));
        }

        return $this->connections[$name];
    }

    /**
     * Return the first active connection
     *
     * @throws RuntimeExecption If no connection is alive
     *
     * @return Connection
     */
    public function getActiveConnection()
    {
        if ($this->activeConnection) {
            return $this->activeConnection;
        }

        foreach ($this->getConnections() as $conn) {
            if ($conn->isAlive()) {
                return $this->activeConnection = $conn;
            }
        }

        throw new \RuntimeException('No connection alive');
    }

    /**
     * Return the dispatcher of the active connection
     *
     * @return EventDispatcherInterface
     */
    public function getDispatcher()
    {
        return $this->getActiveConnection()->getDispatcher();
    }

    /**
{'fraction_non_alphanumeric': 0.1115595272412799, 'fraction_numerical': 0.0005765350245027386, 'mean_word_length': 1.9607508532423208, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '6236109', 'n_tokens_mistral': 917, 'n_tokens_neox': 876, 'n_words': 231}