BaseUriFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 8
c 1
b 0
f 0
dl 0
loc 33
ccs 0
cts 12
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A createUri() 0 6 1
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