Storekeeper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 45
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getRepository() 0 3 1
A __construct() 0 4 1
A getState() 0 3 1
A add() 0 9 1
A setState() 0 3 1
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