1 | <?php |
||
17 | class CheckRoutes extends Command |
||
18 | { |
||
19 | use LogsErrors; |
||
20 | |||
21 | public static $checkedRoutesNum = 0; |
||
22 | |||
23 | public static $skippedRoutesNum = 0; |
||
24 | |||
25 | protected $signature = 'check:routes'; |
||
26 | |||
27 | protected $description = 'Checks the validity of route definitions'; |
||
28 | |||
29 | public function handle(ErrorPrinter $errorPrinter) |
||
30 | { |
||
31 | event('microscope.start.command'); |
||
32 | $this->info('Checking route definitions...'); |
||
33 | |||
34 | $errorPrinter->printer = $this->output; |
||
35 | app(Filesystem::class)->delete(app()->getCachedRoutesPath()); |
||
36 | |||
37 | $routes = app(Router::class)->getRoutes()->getRoutes(); |
||
38 | $this->checkRouteDefinitions($errorPrinter, $routes); |
||
39 | // checks calls like this: route('admin.user') |
||
40 | $this->getOutput()->writeln( |
||
41 | ' - '.CheckRoutes::$checkedRoutesNum. |
||
42 | ' Route:: definitions were checked. ('. |
||
43 | CheckRoutes::$skippedRoutesNum.' skipped)' |
||
44 | ); |
||
45 | $this->info('Checking route names exists...'); |
||
46 | Psr4Classes::check([CheckRouteCalls::class]); |
||
47 | BladeFiles::check([CheckRouteCalls::class]); |
||
48 | |||
49 | $this->getOutput()->writeln(' - '.CheckRouteCalls::$checkedRouteCallsNum. |
||
50 | ' route(...) calls were checked. (' |
||
51 | .CheckRouteCalls::$skippedRouteCallsNum.' skipped)'); |
||
52 | |||
53 | event('microscope.finished.checks', [$this]); |
||
54 | |||
55 | return $errorPrinter->hasErrors() ? 1 : 0; |
||
56 | } |
||
57 | |||
58 | private function getRouteId($route) |
||
68 | |||
69 | private function checkRouteDefinitions($errorPrinter, $routes) |
||
98 | } |
||
99 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.