Completed
Pull Request — master (#128)
by Fabien
10:52
created

Collector::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Http\HttplugBundle\Collector;
4
5
use Exception;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
9
10
class Collector extends DataCollector
11
{
12
    /**
13
     * @var ProfileStack[]
14
     */
15
    private $stacks;
16
17
    /**
18
     * @var array
19
     */
20
    private $clients;
21
22
    /**
23
     * @param array $clients
24
     */
25
    public function __construct(array $clients)
26
    {
27
        $this->stacks = [];
28
        $this->clients = $clients;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function collect(Request $request, Response $response, Exception $exception = null)
35
    {
36
        // We do not need to collect any data from the Symfony Request and Response
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getName()
43
    {
44
        return 'httplug';
45
    }
46
47
    /**
48
     * @param ProfileStack $stack
49
     */
50
    public function addStack(ProfileStack $stack)
51
    {
52
        $this->stacks[] = $stack;
53
    }
54
55
    /**
56
     * @return ProfileStack[]
57
     */
58
    public function getStacks()
59
    {
60
        return $this->stacks;
61
    }
62
63
    /**
64
     * @return ProfileStack
65
     */
66
    public function getCurrentStack()
67
    {
68
        return end($this->stacks);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression end($this->stacks); of type Http\HttplugBundle\Collector\ProfileStack|false adds false to the return on line 68 which is incompatible with the return type documented by Http\HttplugBundle\Colle...lector::getCurrentStack of type Http\HttplugBundle\Collector\ProfileStack. It seems like you forgot to handle an error condition.
Loading history...
69
    }
70
71
    /**
72
     * @return ProfileStack[]
73
     */
74
    public function getSuccessfulStacks()
75
    {
76
        return array_filter($this->stacks, function (ProfileStack $stack) {
77
            return $stack->isSuccessful();
0 ignored issues
show
Bug introduced by
The method isSuccessful() does not seem to exist on object<Http\HttplugBundle\Collector\ProfileStack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
        });
79
    }
80
81
    /**
82
     * @return ProfileStack[]
83
     */
84
    public function getFailedStacks()
85
    {
86
        return array_filter($this->stacks, function (ProfileStack $stack) {
87
            return !$stack->isSuccessful();
0 ignored issues
show
Bug introduced by
The method isSuccessful() does not seem to exist on object<Http\HttplugBundle\Collector\ProfileStack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
88
        });
89
    }
90
91
    /**
92
     * @return array
93
     */
94
    public function getClients()
95
    {
96
        return $this->clients;
97
    }
98
99
    /**
100
     * @param $client
101
     *
102
     * @return ProfileStack[]
103
     */
104
    public function getClientStacks($client)
105
    {
106
        return array_filter($this->stacks, function (ProfileStack $stack) use ($client) {
107
           return $stack->getClient() == $client;
108
        });
109
    }
110
}
111