BaseUriFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
/**
4
 * This file is part of coisa/http.
5
 *
6
 * (c) Felipe Sayão Lobato Abreu <[email protected]>
7
 *
8
 * This source file is subject to the license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
declare(strict_types=1);
13
14
namespace CoiSA\Http\Message;
15
16
use Psr\Http\Message\UriFactoryInterface;
17
use Psr\Http\Message\UriInterface;
18
19
/**
20
 * Class BaseUriFactory
21
 *
22
 * @package CoiSA\Http\Message
23
 */
24
final class BaseUriFactory implements UriFactoryInterface
25
{
26
    /** @var UriInterface */
27
    private $baseUrl;
28
29
    /** @var UriFactoryInterface */
30
    private $uriFactory;
31
32
    /**
33
     * BaseUriFactory constructor.
34
     *
35
     * @param UriInterface $baseUrl
36
     * @param UriFactoryInterface $uriFactory
37
     */
38
    public function __construct(
39
        UriInterface $baseUrl,
40
        UriFactoryInterface $uriFactory
41
    ) {
42
        $this->baseUrl    = $baseUrl;
43
        $this->uriFactory = $uriFactory;
44
    }
45
46
    /**
47
     * @param string $uri
48
     *
49
     * @return UriInterface
50
     */
51
    public function createUri(string $uri = ''): UriInterface
52
    {
53
        $baseUrl = (string) $this->baseUrl;
54
        $uri = $baseUrl . '/' . ltrim('/', $uri);
55
56
        return $this->uriFactory->createUri($uri);
57
    }
58
}
59