<commit_before><?php

namespace Buzz\Util;

class Url
{
    private $url;
    private $components;

    /**
     * Constructor.
     *
     * @param string $url The URL
     *
     * @throws InvalidArgumentException If the URL is invalid
     */
    public function __construct($url)
    {
        $components = parse_url($url);

        if (false === $components) {
            throw new \InvalidArgumentException(sprintf('The URL "%s" is invalid.', $url));
        }

        // support scheme-less URLs
        if (!isset($components['host']) && 0 !== strpos($components['path'], '/')) {
            list($host, $path) = explode('/', $components['path'], 2);
            $components['host'] = $host;
            $components['path'] = '/'.$path;
        }

        $this->url = $url;
        $this->components = $components;
    }

    public function getUrl()
    {
        return $this->url;
    }

    public function getScheme()
    {
        return $this->parseUrl('scheme');
    }

    public function getHostname()
    {
        return $this->parseUrl('host');
    }

    public function getPort()
    {
        return $this->parseUrl('port');<commit_msg>made url slightly more flexible<commit_after><?php

namespace Buzz\Util;

class Url
{
    private $url;
    private $components;

    /**
     * Constructor.
     *
     * @param string $url The URL
     *
     * @throws InvalidArgumentException If the URL is invalid
     */
    public function __construct($url)
    {
        $components = parse_url($url);

        if (false === $components) {
            throw new \InvalidArgumentException(sprintf('The URL "%s" is invalid.', $url));
        }

        // support scheme-less URLs
        if (!isset($components['host']) && isset($components['path'])) {
            $pos = strpos($components['path'], '/');
            if (false === $pos) {
                $components['host'] = $components['path'];
                unset($components['path']);
            } elseif (0 !== $pos) {
                list($host, $path) = explode('/', $components['path'], 2);
                $components['host'] = $host;
                $components['path'] = '/'.$path;
            }
        }

        $this->url = $url;
        $this->components = $components;
    }

    public function getUrl()
    {
        return $this->url;
    }

    public function getScheme()
    {
        return $this->parseUrl('scheme');
    }

    public function getHostname()
    {
        return $this->parseUrl('host');
    }

    public function getPort()
    {
        return $this->parseUrl('port');
{'fraction_non_alphanumeric': 0.15893271461716937, 'fraction_numerical': 0.0015467904098994587, 'mean_word_length': 1.959954233409611, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '3179571', 'n_tokens_mistral': 737, 'n_tokens_neox': 713, 'n_words': 169}