Storekeeper::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 9
rs 10
1
<?php
2
3
namespace MiladRahimi\PhpRouter\Routing;
4
5
use Closure;
6
7
/**
8
 * It adds new routes with an existing state (attributes) into a Route repository
9
 */
10
class Storekeeper
11
{
12
    private Repository $repository;
13
14
    private State $state;
15
16
    public function __construct(Repository $repository, State $state)
17
    {
18
        $this->repository = $repository;
19
        $this->state = $state;
20
    }
21
22
    /**
23
     * Add a new route
24
     *
25
     * @param string $method
26
     * @param string $path
27
     * @param Closure|string|array $controller
28
     * @param string|null $name
29
     */
30
    public function add(string $method, string $path, $controller, ?string $name = null): void
31
    {
32
        $this->repository->save(
33
            $method,
34
            $this->state->getPrefix() . $path,
35
            $controller,
36
            $name,
37
            $this->state->getMiddleware(),
38
            $this->state->getDomain()
39
        );
40
    }
41
42
    public function getState(): State
43
    {
44
        return $this->state;
45
    }
46
47
    public function setState(State $state): void
48
    {
49
        $this->state = $state;
50
    }
51
52
    public function getRepository(): Repository
53
    {
54
        return $this->repository;
55
    }
56
}
57