<commit_before><?php
namespace Wisembly\AmqpBundle;

use InvalidArgumentException;

/**
 * Value object representing an URI connection
 *
 * @link https://www.rabbitmq.com/uri-spec.html
 * @author <NAME> <<EMAIL>>
 */
class UriConnection extends Connection
{
    public function __construct(string $name, string $uri)
    {
        $parse = $this->parseUri($uri);

        parent::__construct(
            $name,
            $parse['host'],
            $parse['port'] ?? null,
            $parse['login'] ?? null,
            $parse['password'] ?? null,
            $parse['vhost'] ?? null,
            $parse['query'] ?? null
        );
    }

    private function parseUri(string $uri): array
    {
        if (false === $parse = parse_url($uri)) {
            throw new InvalidArgumentException('Could not parse uri');
        }

        if (!isset($parse['scheme'])) {
            throw new InvalidArgumentException('Missing scheme.');
        }

        if (!in_array(strtolower($parse['scheme']), ['amqp', 'amqps'])) {
            throw new InvalidArgumentException(sprintf('Invalid scheme. Expected "amqp(s)", had "%s"', $parse['scheme']));
        }

        if (isset($parse['path'], $parse['path'][0]) && '/' === $parse['path'][0]) {
            $parse['path'] = substr($parse['path'], 1);
        }

        return [<commit_msg>Remove superfluous ?? operator in UriConnection<commit_after><?php
namespace Wisembly\AmqpBundle;

use InvalidArgumentException;

/**
 * Value object representing an URI connection
 *
 * @link https://www.rabbitmq.com/uri-spec.html
 * @author <NAME> <<EMAIL>>
 */
class UriConnection extends Connection
{
    public function __construct(string $name, string $uri)
    {
        $parse = $this->parseUri($uri);

        parent::__construct(
            $name,
            $parse['host'],
            $parse['port'],
            $parse['login'],
            $parse['password'],
            $parse['vhost'],
            $parse['query']
        );
    }

    private function parseUri(string $uri): array
    {
        if (false === $parse = parse_url($uri)) {
            throw new InvalidArgumentException('Could not parse uri');
        }

        if (!isset($parse['scheme'])) {
            throw new InvalidArgumentException('Missing scheme.');
        }

        if (!in_array(strtolower($parse['scheme']), ['amqp', 'amqps'])) {
            throw new InvalidArgumentException(sprintf('Invalid scheme. Expected "amqp(s)", had "%s"', $parse['scheme']));
        }

        if (isset($parse['path'], $parse['path'][0]) && '/' === $parse['path'][0]) {
            $parse['path'] = substr($parse['path'], 1);
        }

        return [
{'fraction_non_alphanumeric': 0.17365269461077845, 'fraction_numerical': 0.002245508982035928, 'mean_word_length': 2.453488372093023, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '621310', 'n_tokens_mistral': 754, 'n_tokens_neox': 735, 'n_words': 165}