ResolverCacheStage   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
c 1
b 0
f 1
dl 0
loc 38
ccs 17
cts 17
cp 1
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A processCommand() 0 4 2
A hasControllerName() 0 7 3
A parseCacheForControllerDefinition() 0 10 3
1
<?php
2
3
namespace Nip\Dispatcher\Resolver\Pipeline\Stages;
4
5
use Nip\Dispatcher\Resolver\Cache\ResolverCache;
6
use Nip\Dispatcher\Resolver\ClassResolver;
7
8
/**
9
 * Class ResolverCacheStage
10
 * @package Nip\Dispatcher\Resolver\Pipeline\Stages
11
 */
12
class ResolverCacheStage extends AbstractStage
13
{
14
    /**
15
     * @return void
16
     * @throws \Exception
17
     */
18 4
    public function processCommand()
19
    {
20 4
        if ($this->hasControllerName()) {
21 3
            $this->parseCacheForControllerDefinition();
22
        }
23 4
    }
24
25
    /**
26
     * @return bool
27
     */
28 4
    public function hasControllerName()
29
    {
30 4
        $action = $this->getCommand()->getAction();
31 4
        if (is_array($action) && isset($action['controller'])) {
32 3
            return true;
33
        }
34 1
        return false;
35
    }
36
37
    /**
38
     * @throws \Exception
39
     */
40 3
    protected function parseCacheForControllerDefinition()
41
    {
42 3
        $action = $this->getCommand()->getAction();
43 3
        $class = ResolverCache::resolveFromAction($action);
44 3
        if ($class) {
45 1
            $instance = ClassResolver::newController($class);
46
47 1
            if ($instance) {
0 ignored issues
show
introduced by
$instance is of type Nip\Controllers\Controller, thus it always evaluated to true.
Loading history...
48 1
                $this->getCommand()->setActionParam('instance', $instance);
49 1
                return;
50
            }
51
        }
52 2
    }
53
}
54