Factory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 35
rs 10
c 0
b 0
f 0
ccs 8
cts 8
cp 1
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setSchemeCollection() 0 4 1
A newInstance() 0 11 2
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource;
6
7
use BEAR\Resource\Exception\UriException;
8
use Override;
9
use Ray\Di\Di\Inject;
10
11
use function is_string;
12
13
final class Factory implements FactoryInterface
14
{
15
    public function __construct(
16
        private SchemeCollectionInterface $scheme,
17
        private readonly UriFactory $uri,
18 66
    ) {
19
    }
20 66
21 66
    /**
22
     * Set scheme collection
23
     *
24
     * @codeCoverageIgnore
25
     */
26
    #[Inject(optional: true)]
27
    public function setSchemeCollection(SchemeCollectionInterface $scheme): void
28
    {
29
        $this->scheme = $scheme;
30
    }
31
32
    /**
33
     * {@inheritDoc}
34
     *
35
     * @throws UriException
36
     */
37
    #[Override]
38
    public function newInstance($uri): ResourceObject
39 57
    {
40
        if (is_string($uri)) {
41 57
            $uri = ($this->uri)($uri);
42 21
        }
43
44 55
        $ro = $this->scheme->getAdapter($uri)->get($uri);
45
        $ro->uri = $uri;
46 53
47
        return $ro;
48
    }
49
}
50