Passed
Pull Request — main (#8)
by Jesús
02:40 queued 28s
created

MappingInterfaces   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 31
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A builtInInjections() 0 3 1
A getAll() 0 3 1
A add() 0 4 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Router;
6
7
use Gacela\Router\Entities\Request;
8
9
final class MappingInterfaces
10
{
11
    /** @var array<class-string, callable|class-string|object> */
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<class-string, callable|class-string|object> at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in array<class-string, callable|class-string|object>.
Loading history...
12
    private array $mappingInterfaces = [];
13
14 74
    public function __construct()
15
    {
16 74
        $this->builtInInjections();
17
    }
18
19
    /**
20
     * @param class-string $name
21
     * @param callable|class-string|object $instance
22
     */
23 74
    public function add(string $name, mixed $instance): self
24
    {
25 74
        $this->mappingInterfaces[$name] = $instance;
26 74
        return $this;
27
    }
28
29
    /**
30
     * @return array<class-string, callable|class-string|object>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<class-string, callable|class-string|object> at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in array<class-string, callable|class-string|object>.
Loading history...
31
     */
32 51
    public function getAll(): array
33
    {
34 51
        return $this->mappingInterfaces;
35
    }
36
37 74
    private function builtInInjections(): void
38
    {
39 74
        $this->add(Request::class, Request::fromGlobals());
40
    }
41
}
42