Passed
Branch v2-dev (5d4b18)
by Henri
01:19
created

Helper   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 11
Bugs 0 Features 1
Metric Value
eloc 14
dl 0
loc 42
rs 10
c 11
b 0
f 1
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A inSave() 0 3 1
A getRoutes() 0 3 1
A defineHost() 0 4 1
A updateRoute() 0 4 1
A setRoutes() 0 3 1
A getInstance() 0 4 2
A getHost() 0 3 1
1
<?php
2
3
namespace HnrAzevedo\Router;
4
5
trait Helper
6
{
7
    protected array $routes = [];
8
    protected static Router $instance;
9
    protected string $host = '';
10
11
    public static function getInstance(): RouterInterface
12
    {
13
        self::$instance = (!isset(self::$instance)) ? new Router() : self::$instance;
14
        return self::$instance;
15
    }
16
17
    protected static function updateRoute(array $route, $key): RouterInterface
18
    {
19
        self::getInstance()->getRoutes()[$key] = $route;
20
        return self::getInstance();
21
    }
22
23
    public static function defineHost(string $host): Router
24
    {
25
        self::getInstance()->host = $host;
0 ignored issues
show
Bug introduced by
The property host is declared protected in HnrAzevedo\Router\Router and cannot be accessed from this context.
Loading history...
26
        return self::getInstance();
27
    }
28
29
    protected function inSave(): array
30
    {
31
        return end($this->routes);
32
    }
33
34
    protected function getHost(): string
35
    {
36
        return $this->host;
37
    }
38
39
    protected function getRoutes(): array
40
    {
41
        return $this->routes;
42
    }
43
44
    protected function setRoutes(array $routes): void
45
    {
46
        $this->routes =  $routes;
47
    }
48
49
}
50