ClassInstanceStage   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 12
c 1
b 0
f 1
dl 0
loc 30
ccs 12
cts 14
cp 0.8571
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A processCommand() 0 4 3
A buildController() 0 14 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Nip\Dispatcher\Resolver\Pipeline\Stages;
5
6
use Nip\Dispatcher\Exceptions\InvalidCommandException;
7
use Nip\Dispatcher\Resolver\Cache\ResolverCache;
8
use Nip\Dispatcher\Resolver\ClassResolver;
9
10
/**
11
 * Class ClassInstanceStage
12
 * @package Nip\Dispatcher\Resolver\Pipeline\Stages
13
 */
14
class ClassInstanceStage extends AbstractStage
15
{
16
    /**
17
     * @return void
18
     * @throws \Exception
19
     */
20 4
    public function processCommand()
21
    {
22 4
        if (!$this->hasInstanceAction() && $this->hasClassAction()) {
23 2
            $this->buildController();
24
        }
25 4
    }
26
27
    /**
28
     * @throws \Exception
29
     */
30 2
    protected function buildController()
31
    {
32 2
        $controllerNames = $this->getCommand()->getActionParam('class');
33 2
        $controller = ClassResolver::resolveFromClasses($controllerNames);
34
35 2
        if ($controller) {
36 2
            ResolverCache::setFromAction($this->getCommand()->getAction(), get_class($controller));
37 2
            ResolverCache::save();
38 2
            $this->getCommand()->setActionParam('instance', $controller);
39 2
            return;
40
        }
41
42
        throw new InvalidCommandException(
43
            "No valid controllers found for [" . print_r($controllerNames, true) . "]"
0 ignored issues
show
Bug introduced by
Are you sure print_r($controllerNames, true) of type string|true can be used in concatenation? ( Ignorable by Annotation )

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

43
            "No valid controllers found for [" . /** @scrutinizer ignore-type */ print_r($controllerNames, true) . "]"
Loading history...
44
        );
45
    }
46
}
47