Issues (6)

src/ArtisanUI.php (1 issue)

1
<?php
2
3
namespace Desemax\ArtisanUI;
4
5
use Illuminate\Support\Facades\Artisan;
6
use Symfony\Component\Console\Command\Command;
7
8
class ArtisanUI
9
{
10
    public function commands()
11
    {
12
        return array_values(array_filter(Artisan::all(), function ($command) {
13
            return ! in_array($this->getNamespace($command), $this->ignoredNamespaces());
14
        }));
15
    }
16
17
    public function names()
18
    {
19
        return array_keys($this->commands());
20
    }
21
22
    public function namespaces()
23
    {
24
        return array_values(array_unique(array_map(function ($command) {
25
            return $this->getNamespace($command);
26
        }, $this->commands())));
27
    }
28
29
    public function getNamespace(Command $command)
30
    {
31
        return explode(':', $command->getName())[0];
0 ignored issues
show
It seems like $command->getName() can also be of type null; however, parameter $string of explode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

31
        return explode(':', /** @scrutinizer ignore-type */ $command->getName())[0];
Loading history...
32
    }
33
34
    public function ignoredNamespaces()
35
    {
36
        return array_merge(
37
            config('artisanui.commands.namespaces.excluded.default'),
38
            config('artisanui.commands.namespaces.excluded.custom')
39
        );
40
    }
41
}
42