GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

MakeEnum   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 8
eloc 22
c 4
b 1
f 1
dl 0
loc 58
rs 10
ccs 26
cts 26
cp 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultNamespace() 0 3 1
A getDocBlock() 0 13 2
A getStub() 0 3 1
A getOptions() 0 4 1
A getArguments() 0 4 1
A replaceClass() 0 7 1
A handle() 0 5 1
1
<?php
2
3
namespace Spatie\Enum\Laravel\Commands;
4
5
use Illuminate\Console\GeneratorCommand;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputOption;
8
9
class MakeEnum extends GeneratorCommand
10
{
11
    protected $name = 'make:enum';
12
13
    protected $description = 'Create a new enum';
14
15 36
    public function handle()
16
    {
17 36
        $this->type = $this->getNameInput();
18
19
        return parent::handle();
20 36
    }
21
22 36
    protected function getStub()
23
    {
24
        return __DIR__.'/../../stubs/enum.php.stub';
25 36
    }
26
27 36
    protected function getDefaultNamespace($rootNamespace)
28
    {
29 36
        return $rootNamespace.'\Enums';
30 36
    }
31
32 36
    protected function replaceClass($stub, $name)
33
    {
34
        $stub = parent::replaceClass($stub, $name);
35 36
36
        $stub = str_replace('/** DummyDocBlock */', $this->getDocBlock(), $stub);
37 36
38
        return $stub;
39 36
    }
40 32
41
    protected function getDocBlock(): string
42 32
    {
43 32
        $methods = $this->option('method');
44 32
45
        if (! empty($methods)) {
46
            $docBlock = PHP_EOL.'/**';
47 36
            $docBlock .= implode('', array_map(function ($method) {
48
                return PHP_EOL.' * @method static self '.$method.'()';
49
            }, $methods));
0 ignored issues
show
Bug introduced by
It seems like $methods can also be of type boolean and string; however, parameter $arr1 of array_map() does only seem to accept array, 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

49
            }, /** @scrutinizer ignore-type */ $methods));
Loading history...
50 36
            $docBlock .= PHP_EOL.' */';
51
        }
52 36
53
        return $docBlock ?? '';
54 36
    }
55 16
56 16
    protected function getArguments()
57
    {
58 16
        return [
59 16
            ['name', InputArgument::REQUIRED, 'The name of the enum'],
60
        ];
61
    }
62 16
63
    protected function getOptions()
64
    {
65 36
        return [
66
            ['method', 'm', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'The method name that should be added to the enum'],
67
        ];
68 32
    }
69
}
70