1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Hyde\Console\Commands; |
6
|
|
|
|
7
|
|
|
use Hyde\Hyde; |
8
|
|
|
use Illuminate\Support\Arr; |
9
|
|
|
use Hyde\Console\Concerns\Command; |
10
|
|
|
use Hyde\Support\Internal\RouteListItem; |
11
|
|
|
|
12
|
|
|
use function array_keys; |
13
|
|
|
use function json_encode; |
14
|
|
|
use function array_values; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Display the list of site routes. |
18
|
|
|
*/ |
19
|
|
|
class RouteListCommand extends Command |
20
|
|
|
{ |
21
|
|
|
/** @var string */ |
22
|
|
|
protected $signature = 'route:list {--format=txt : The output format (txt or json)}'; |
23
|
|
|
|
24
|
|
|
/** @var string */ |
25
|
|
|
protected $description = 'Display all the registered routes'; |
26
|
|
|
|
27
|
|
|
public function handle(): int |
28
|
|
|
{ |
29
|
|
|
$routes = $this->generate(); |
30
|
|
|
|
31
|
|
|
return match ($this->option('format')) { |
32
|
|
|
'txt' => $this->table($this->makeHeader($routes), $routes) ?? Command::SUCCESS, |
|
|
|
|
33
|
|
|
'json' => $this->writeRaw(json_encode($routes, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)) ?? Command::SUCCESS, |
|
|
|
|
34
|
|
|
default => $this->error("Invalid format provided. Only 'txt' and 'json' are supported.") ?? Command::FAILURE, |
|
|
|
|
35
|
|
|
}; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** @return array<int, array<string, string>> */ |
39
|
|
|
protected function generate(): array |
40
|
|
|
{ |
41
|
|
|
return Arr::map(array_values(Hyde::routes()->all()), RouteListItem::format(...)); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** @param array<int, array<string, string>> $routes */ |
45
|
|
|
protected function makeHeader(array $routes): array |
46
|
|
|
{ |
47
|
|
|
return Arr::map(array_keys($routes[0]), Hyde::makeTitle(...)); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** Write a message without ANSI formatting */ |
51
|
|
|
protected function writeRaw(string $message): void |
52
|
|
|
{ |
53
|
|
|
$this->output->setDecorated(false); |
54
|
|
|
$this->output->writeln($message); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.