Test Failed
Push — master ( a309d2...0e4b58 )
by butschster
17:34 queued 09:02
created

ControllerDeclaration::getInstructions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Scaffolder\Declaration;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Spiral\Prototype\Traits\PrototypeTrait;
9
use Spiral\Reactor\Partial\Method;
10
use Spiral\Router\Annotation\Route;
11
12
/**
13
 * Declares controller.
14
 */
15
class ControllerDeclaration extends AbstractDeclaration implements HasInstructions
16
{
17
    public const TYPE = 'controller';
18
19 2
    public function addAction(string $action): Method
20
    {
21 2
        return $this->class
22 2
            ->addMethod($action)
23 2
            ->addComment(
24 2
                'Please, don\'t forget to configure the Route attribute or remove it and register the route manually.'
25 2
            )
26 2
            ->setPublic()
27 2
            ->addAttribute(Route::class, ['route' => 'path', 'name' => 'name'])
28 2
            ->setReturnType(ResponseInterface::class);
29
    }
30
31 1
    public function addPrototypeTrait(): void
32
    {
33 1
        $this->namespace->addUse(PrototypeTrait::class);
34 1
        $this->class->addTrait(PrototypeTrait::class);
35
    }
36
37 4
    public function declare(): void
38
    {
39 4
        $this->namespace->addUse(Route::class);
40 4
        $this->namespace->addUse(ResponseInterface::class);
41
    }
42
43
    public function getInstructions(): array
44
    {
45
        return [
46
            'Read more about Controllers in the documentation: https://spiral.dev/docs/http-routing',
47
        ];
48
    }
49
}
50