Passed
Push — main ( 94bc2d...615377 )
by Chema
03:24 queued 56s
created

Bindings::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Router\Configure;
6
7
use Gacela\Router\Entities\Request;
8
9
final class Bindings
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 $bindings = [];
13
14 97
    public function __construct()
15
    {
16 97
        $this->addBuiltInBindings();
17
    }
18
19
    /**
20
     * @param class-string $name
21
     * @param callable|class-string|object $instance
22
     */
23 97
    public function bind(string $name, mixed $instance): self
24
    {
25 97
        $this->bindings[$name] = $instance;
26 97
        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 61
    public function getAllBindings(): array
33
    {
34 61
        return $this->bindings;
35
    }
36
37 97
    private function addBuiltInBindings(): void
38
    {
39 97
        $this->bind(Request::class, Request::fromGlobals());
40
    }
41
}
42