LoadRoutesFromFile::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 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