Passed
Push — main ( e724aa...57676c )
by Peter
02:58
created

RouterBootstrapper::setRoutePaths()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Bootstrappers\Http;
6
7
use Opulence\Framework\Configuration\Config;
8
use Opulence\Framework\Routing\Bootstrappers\RouterBootstrapper as BaseBootstrapper;
9
use Opulence\Routing\Router;
10
11
/**
12
 * @SuppressWarnings(PHPMD.StaticAccess)
13
 *
14
 * Defines the router bootstrapper
15
 */
16
class RouterBootstrapper extends BaseBootstrapper
17
{
18
    protected ?array $routePaths = null;
19
20
    /**
21
     * @return array
22
     */
23
    public function getRoutePaths(): array
24
    {
25
        global $abterModuleManager;
26
27
        if ($this->routePaths !== null) {
28
            return $this->routePaths;
29
        }
30
31
        $this->routePaths = $abterModuleManager->getRoutePaths() ?: [];
32
33
        return $this->routePaths;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->routePaths returns the type null which is incompatible with the type-hinted return array.
Loading history...
34
    }
35
36
    /**
37
     * @param array $routePaths
38
     *
39
     * @return $this
40
     */
41
    public function setRoutePaths(array $routePaths): self
42
    {
43
        $this->routePaths = $routePaths;
44
45
        return $this;
46
    }
47
48
49
    /**
50
     * Configures the router, which is useful for things like caching
51
     *
52
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
53
     *
54
     * @param Router $router The router to configure
55
     */
56
    protected function configureRouter(Router $router)
57
    {
58
        $httpConfigPath   = Config::get('paths', 'config.http');
59
        $routesConfigPath = "$httpConfigPath/routes.php";
60
61
        require $routesConfigPath;
62
63
        foreach ($this->getRoutePaths() as $path) {
64
            require $path;
65
        }
66
    }
67
}
68