AbstractDecorator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 71
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
getComponentName() 0 1 ?
A __call() 0 7 1
A getBenchmarkName() 0 4 1
A getProfiler() 0 4 1
A setProfiler() 0 4 1
A getDecorated() 0 4 1
A setDecorated() 0 4 1
1
<?php
2
/**
3
 * @author @fabfuel <[email protected]>
4
 * @created 21.06.15, 08:38 
5
 */
6
namespace Fabfuel\Prophiler\Decorator;
7
8
use Fabfuel\Prophiler\ProfilerInterface;
9
10
abstract class AbstractDecorator
11
{
12
    /**
13
     * @var ProfilerInterface
14
     */
15
    private $profiler;
16
17
    /**
18
     * @var mixed
19
     */
20
    private $decorated;
21
22
    /**
23
     * @return string
24
     */
25
    abstract public function getComponentName();
26
27
    /**
28
     * @param string $name
29
     * @param array $arguments
30
     * @return mixed
31
     */
32 2
    public function __call($name, array $arguments)
33
    {
34 2
        $benchmark = $this->getProfiler()->start($this->getBenchmarkName($name), $arguments, $this->getComponentName());
35 2
        $result = call_user_func_array([$this->getDecorated(), $name], $arguments);
36 2
        $this->getProfiler()->stop($benchmark);
37 2
        return $result;
38
    }
39
40
    /**
41
     * @param string $methodName
42
     * @return string
43
     */
44 2
    public function getBenchmarkName($methodName)
45
    {
46 2
        return sprintf('%s::%s', get_class($this->getDecorated()), $methodName);
47
    }
48
49
    /**
50
     * @return ProfilerInterface
51
     */
52 3
    public function getProfiler()
53
    {
54 3
        return $this->profiler;
55
    }
56
57
    /**
58
     * @param ProfilerInterface $profiler
59
     */
60 4
    public function setProfiler(ProfilerInterface $profiler)
61
    {
62 4
        $this->profiler = $profiler;
63 4
    }
64
65
    /**
66
     * @return mixed
67
     */
68 4
    public function getDecorated()
69
    {
70 4
        return $this->decorated;
71
    }
72
73
    /**
74
     * @param mixed $decorated
75
     */
76 4
    public function setDecorated($decorated)
77
    {
78 4
        $this->decorated = $decorated;
79
    }
80
}