Completed
Push — master ( 56570e...2c8793 )
by Gabriel
07:17
created

ResolverCacheStage::processCommand()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
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
    /**
16
     * @return void
17
     * @throws \Exception
18
     */
19 4
    public function processCommand()
20
    {
21 4
        if ($this->hasControllerName()) {
22 3
            $this->parseCacheForControllerDefinition();
23
        }
24 4
    }
25
26
    /**
27
     * @return bool
28
     */
29 4 View Code Duplication
    public function hasControllerName()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
    {
31 4
        $action = $this->getCommand()->getAction();
32 4
        if (is_array($action) && isset($action['controller'])) {
33 3
            return true;
34
        }
35 1
        return false;
36
    }
37
38
    /**
39
     * @throws \Exception
40
     */
41 3
    protected function parseCacheForControllerDefinition()
42
    {
43 3
        $action = $this->getCommand()->getAction();
44 3
        $class = ResolverCache::resolveFromAction($action);
45 3
        if ($class) {
46 1
            $instance = ClassResolver::newController($class);
47
48 1
            if ($instance) {
49 1
                $this->getCommand()->setActionParam('instance', $instance);
50 1
                return;
51
            }
52
        }
53 2
    }
54
}
55