Passed
Push — master ( 865ea9...f5a1ef )
by butschster
29:08 queued 21:20
created

ControllerCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 20
dl 0
loc 34
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A perform() 0 15 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Scaffolder\Command;
6
7
use Spiral\Console\Attribute\Argument;
8
use Spiral\Console\Attribute\AsCommand;
9
use Spiral\Console\Attribute\Option;
10
use Spiral\Console\Attribute\Question;
11
use Spiral\Scaffolder\Declaration\ControllerDeclaration;
12
13
#[AsCommand(name: 'create:controller', description: 'Create controller declaration')]
14
class ControllerCommand extends AbstractCommand
15
{
16
    #[Argument(description: 'Controller name')]
17
    #[Question(question: 'What would you like to name the Controller?')]
18
    private string $name;
0 ignored issues
show
introduced by
The private property $name is not used, and could be removed.
Loading history...
19
20
    #[Option(name: 'action', shortcut: 'a', description: 'Pre-create controller action')]
21
    private array $actions = [];
22
23
    #[Option(name: 'prototype', shortcut: 'p', description: 'Add \Spiral\Prototype\Traits\PrototypeTrait to controller')]
24
    private bool $usePrototype = false;
25
26
    #[Option(shortcut: 'c', description: 'Optional comment to add as class header')]
27
    private ?string $comment = null;
0 ignored issues
show
introduced by
The private property $comment is not used, and could be removed.
Loading history...
28
29
    #[Option(description: 'Optional, specify a custom namespace')]
30
    private ?string $namespace = null;
0 ignored issues
show
introduced by
The private property $namespace is not used, and could be removed.
Loading history...
31
32 4
    public function perform(): int
33
    {
34 4
        $declaration = $this->createDeclaration(ControllerDeclaration::class);
35
36 4
        foreach ($this->actions as $action) {
37 2
            $declaration->addAction($action);
0 ignored issues
show
Bug introduced by
The method addAction() does not exist on Spiral\Scaffolder\Declaration\DeclarationInterface. It seems like you code against a sub-type of Spiral\Scaffolder\Declaration\DeclarationInterface such as Spiral\Scaffolder\Declar...n\ControllerDeclaration. ( Ignorable by Annotation )

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

37
            $declaration->/** @scrutinizer ignore-call */ 
38
                          addAction($action);
Loading history...
38
        }
39
40 4
        if ($this->usePrototype) {
41 1
            $declaration->addPrototypeTrait();
0 ignored issues
show
Bug introduced by
The method addPrototypeTrait() does not exist on Spiral\Scaffolder\Declaration\DeclarationInterface. It seems like you code against a sub-type of Spiral\Scaffolder\Declaration\DeclarationInterface such as Spiral\Scaffolder\Declar...n\ControllerDeclaration. ( Ignorable by Annotation )

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

41
            $declaration->/** @scrutinizer ignore-call */ 
42
                          addPrototypeTrait();
Loading history...
42
        }
43
44 4
        $this->writeDeclaration($declaration);
45
46 4
        return self::SUCCESS;
47
    }
48
}
49