FindInvalidRouteDefinitionsCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A routeFiles() 0 9 2
A handle() 0 7 2
1
<?php
2
3
namespace Juddling\RouteChecker\Commands;
4
5
use DirectoryIterator;
6
use Juddling\RouteChecker\FindInvalidRouteCalls;
7
use Juddling\RouteChecker\FindInvalidRouteDefinitions;
8
use RegexIterator;
9
10
class FindInvalidRouteDefinitionsCommand extends FindInvalidRouteCallsCommand
11
{
12
    protected $signature = 'runtime-errors:route-definitions';
13
    protected $description = 'Checks your route definitions to see if they point to an existing controller action';
14
    protected $routeDefinitions;
15
16
    public function __construct(FindInvalidRouteDefinitions $routeDefinitions)
17
    {
18
        $this->routeDefinitions = $routeDefinitions;
19
20
        parent::__construct(new FindInvalidRouteCalls());
21
    }
22
23
    public function handle()
24
    {
25
        foreach ($this->routeFiles() as $file) {
26
            $this->routeDefinitions->findFunctionCalls($file);
27
        }
28
29
        $this->routeDefinitions->renderTable($this->getOutput());
30
    }
31
32
    /**
33
     * Returns the path to all route files, e.g.:
34
     * routes/api.php
35
     * routes/web.php
36
     *
37
     * @return \Generator
38
     */
39
    protected function routeFiles()
40
    {
41
        $it = new DirectoryIterator(realpath(getcwd()) . '/routes/');
42
        $it = new RegexIterator($it, '(\.php$)');
43
44
        foreach ($it as $file) {
45
            /** @var \SplFileObject $file */
46
            $filepath = $file->getRealPath();
47
            yield $filepath;
48
        }
49
    }
50
}
51