Passed
Branch dev (8b2306)
by Alex
02:48
created

EnhancerAbstractStrategy   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A call() 0 10 2
enhance() 0 1 ?
1
<?php
2
3
/**
4
 * Codeburner Framework.
5
 *
6
 * @author Alex Rohleder <[email protected]>
7
 * @copyright 2016 Alex Rohleder
8
 * @license http://opensource.org/licenses/MIT
9
 */
10
11
namespace Codeburner\Router\Strategies;
12
13
use Codeburner\Router\Route;
14
use Codeburner\Router\Exceptions\BadRouteException;
15
16
/**
17
 * The route enhancer strategy act like a bridge between
18
 * one route and it dispatch strategy. In this "bridge" operations
19
 * are made manipulating the route object.
20
 *
21
 * @author Alex Rohleder <[email protected]>
22
 */
23
24
abstract class EnhancerAbstractStrategy implements StrategyInterface
25
{
26
27
    /**
28
     * Key used to store the real route strategy on metadata.
29
     *
30
     * @var string
31
     */
32
33
    protected $metadataStrategyKey = "strategy";
34
35
    /**
36
     * @inheritdoc
37
     * @throws BadRouteException
38
     */
39
40
    public function call(Route $route)
41
    {
42
        if ($route->hasMetadata($this->metadataStrategyKey)) {
43
               $route->setStrategy($route->getMetadata($this->metadataStrategyKey));
44
        } else $route->setStrategy(null);
45
46
        $this->enhance($route);
47
48
        return $route->call();
49
    }
50
51
    /**
52
     * Manipulate route object before the dispatch.
53
     *
54
     * @param Route $route
55
     * @return mixed
56
     */
57
58
    abstract public function enhance(Route $route);
59
60
}
61