RouteListCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 3 1
A writeRaw() 0 4 1
A handle() 0 8 1
A makeHeader() 0 3 1
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,
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->table($this->makeHeader($routes), $routes) targeting Illuminate\Console\Command::table() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
33
            'json' => $this->writeRaw(json_encode($routes, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)) ?? Command::SUCCESS,
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->writeRaw(json_enc...SON_UNESCAPED_SLASHES)) targeting Hyde\Console\Commands\RouteListCommand::writeRaw() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
34
            default => $this->error("Invalid format provided. Only 'txt' and 'json' are supported.") ?? Command::FAILURE,
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->error('Invalid fo...'json' are supported.') targeting Illuminate\Console\Command::error() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
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(...));
0 ignored issues
show
Bug introduced by
The method routes() does not exist on Hyde\Hyde. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
        return Arr::map(array_values(Hyde::/** @scrutinizer ignore-call */ routes()->all()), RouteListItem::format(...));
Loading history...
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