<commit_before><?php

declare(strict_types=1);

namespace BEAR\Resource;

use BEAR\Resource\Annotation\ContextSchema;
use BEAR\Resource\Exception\UriException;
use function parse_url;

final class UriFactory
{
    /**
     * @var string
     */
    private $schemaHost;

    /**
     * @ContextSchema
     */
    public function __construct(string $schemaHost = 'page://self')
    {
        $this->schemaHost = $schemaHost;
    }

    public function __invoke($uri, array $query = [])
    {
        if (array_keys(parse_url($uri)) === ['path']) {
            $uri = $this->schemaHost . $uri;
        }

        return new Uri($uri, $query);
    }

    /**
     * @throws UriException
     */
    private function validate(string $uri)
    {
        if (! filter_var($uri, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)) {
            $msg = is_string($uri) ? $uri : gettype($uri);

            throw new UriException($msg, 500);
        }
    }
}<commit_msg>check scheme<commit_after><?php

declare(strict_types=1);

namespace BEAR\Resource;

use BEAR\Resource\Annotation\ContextSchema;
use BEAR\Resource\Exception\UriException;
use function parse_url;

final class UriFactory
{
    /**
     * @var string
     */
    private $schemaHost;

    /**
     * @ContextSchema
     */
    public function __construct(string $schemaHost = 'page://self')
    {
        $this->schemaHost = $schemaHost;
    }

    public function __invoke($uri, array $query = [])
    {
        if (! array_key_exists('scheme', parse_url($uri))) {
            $uri = $this->schemaHost . $uri;
        }

        return new Uri($uri, $query);
    }

    /**
     * @throws UriException
     */
    private function validate(string $uri)
    {
        if (! filter_var($uri, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)) {
            $msg = is_string($uri) ? $uri : gettype($uri);

            throw new UriException($msg, 500);
        }
    }
}
{'fraction_non_alphanumeric': 0.13787721123829344, 'fraction_numerical': 0.004162330905306972, 'mean_word_length': 2.38556338028169, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5729743', 'n_tokens_mistral': 622, 'n_tokens_neox': 594, 'n_words': 119}