LoadRoutesFromFile   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 33
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A loadRoutes() 0 12 3
A __construct() 0 4 1
1
<?php
2
3
namespace Mosaic\Routing\Loaders;
4
5
use InvalidArgumentException;
6
use Mosaic\Routing\RouteLoader;
7
use Mosaic\Routing\Router;
8
9
class LoadRoutesFromFile implements RouteLoader
10
{
11
    /**
12
     * @var string[]
13
     */
14
    private $paths;
15
16
    /**
17
     * @param string ...$paths
18
     */
19 4
    public function __construct(string ...$paths)
20
    {
21 4
        $this->paths = $paths;
22 4
    }
23
24
    /**
25
     * @param Router $router
26
     *
27
     * @return Router
28
     */
29 2
    public function loadRoutes(Router $router) : Router
30
    {
31 2
        foreach ($this->paths as $path) {
32 2
            if (!file_exists($path)) {
33 1
                throw new InvalidArgumentException('Route file does not exist at [' . $path . ']');
34
            }
35
36 1
            include_once $path;
37
        }
38
39 1
        return $router;
40
    }
41
}
42