Completed
Push — 1.x ( 372351...30eb05 )
by Akihito
18s
created

UriFactory::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 10
cc 3
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource;
6
7
use BEAR\Resource\Annotation\ContextScheme;
8
use function parse_url;
9
10
final class UriFactory
11
{
12
    /**
13
     * @var string
14
     */
15
    private $schemaHost;
16
17
    /**
18
     * @ContextScheme
19
     */
20
    public function __construct(string $schemaHost = 'page://self')
21
    {
22
        $this->schemaHost = $schemaHost;
23
    }
24
25
    public function __invoke($uri, array $query = [])
26
    {
27
        if (! array_key_exists('scheme', parse_url($uri))) {
28
            $uri = $this->schemaHost . $uri;
29
        }
30
31
        return new Uri($uri, $query);
32
    }
33
}
34