Helper::updateRoute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace HnrAzevedo\Router;
6
7
trait Helper
8
{
9
    protected array $routes = [];
10
    protected static Router $instance;
11
    protected string $host = '';
12
    private string $prefix = '';
13
    protected ?string $group = null;
14
    protected bool $loaded = false;
15
16
    public static function getInstance(): RouterInterface
17
    {
18
        self::$instance = (!isset(self::$instance)) ? new Router() : self::$instance;
19
        return self::$instance;
20
    }
21
22
    protected function loaded(): bool
23
    {
24
        return $this->loaded;
25
    }
26
27
    protected static function updateRoute(array $route, $key): RouterInterface
28
    {
29
        $routeG = self::getInstance()->getRoutes();
30
        $routeG[$key] = $route;
31
        self::getInstance()->setRoutes($routeG);
32
        return self::getInstance();
33
    }
34
35
    public static function defineHost(string $host): Router
36
    {
37
        self::getInstance()->setHost($host);
38
        return self::getInstance();
39
    }
40
41
    protected function inSave(): array
42
    {
43
        return end($this->routes);
44
    }
45
46
    protected function setHost(string $host): void
47
    {
48
        $this->host = $host;
49
    }
50
51
    protected function getHost(): string
52
    {
53
        return $this->host;
54
    }
55
56
    protected function getRoutes(): array
57
    {
58
        return $this->routes;
59
    }
60
61
    protected function setRoutes(array $routes): void
62
    {
63
        $this->routes =  $routes;
64
    }
65
66
    protected function getGroup(): ?string
67
    {
68
        return $this->group;
69
    }
70
71
    protected function setGroup(?string $group): void
72
    {
73
        $this->group = $group;
74
    }
75
76
    protected function getPrefix(): ?string
77
    {
78
        return $this->prefix;
79
    }
80
81
    protected function setPrefix(string $prefix): void
82
    {
83
        $this->prefix = $prefix;
84
    }
85
}
86