StopwatchWebService::__call()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace SkautisBundle\Skautis\Wsdl;
4
5
use Skautis\Wsdl\WebService;
6
use Symfony\Component\Stopwatch\Stopwatch;
7
8
/**
9
 * Trida pro zobrazovani requestu v timeline panelu v profileru
10
 */
11
class StopwatchWebService extends WebService
12
{
13
14
    /**
15
     * Profilovani
16
     *
17
     * @var Stopwatch
18
     */
19
    protected $stopwatch;
20
21
    /**
22
     * @var int[]
23
     */
24
    protected $counter = [];
25
26
    public function setStopwatch(Stopwatch $stopwatch)
27
    {
28
        $this->stopwatch = $stopwatch;
29
    }
30
31
    protected function getWatchName($function_name)
32
    {
33
        $name = $function_name;
34
35
        if (isset($this->counter[$function_name])) {
36
            $name .= ' - ' . $this->counter[$function_name];
37
            $this->counter[$function_name]++;
38
        } else {
39
            $this->counter[$function_name] = 0;
40
        }
41
42
        return $name;
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function __call($function_name, $arguments)
49
    {
50
        return $this->call($function_name, $arguments);
51
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56
    public function call($function_name, array $arguments = [])
57
    {
58
        $name = $this->getWatchName($function_name);
59
        $this->stopwatch->start($name, "skautis");
60
61
        try {
62
            $result = parent::call($function_name, $arguments);
63
        } catch (\Exception $e) {
64
            throw $e;
65
        } finally {
66
            $this->stopwatch->stop($name);
67
        }
68
69
        return $result;
70
    }
71
72
}
73