Passed
Push — master ( f11675...241e69 )
by Novikov
02:38
created

RestrictionsCollector   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 59
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A collect() 0 5 1
A setStorageManager() 0 3 1
A getName() 0 3 1
A getRestrictionsCount() 0 3 1
A getRestrictions() 0 3 1
A __sleep() 0 3 1
1
<?php
2
3
namespace NV\RequestLimitBundle\DataCollector;
4
5
use NV\RequestLimitBundle\Storage\StorageManager;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
9
10
class RestrictionsCollector implements DataCollectorInterface
11
{
12
    /**
13
     * @var array
14
     */
15
    private $data;
16
17
    /** @var StorageManager $storageManager */
18
    private $storageManager;
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function collect(Request $request, Response $response, \Exception $exception = null)
24
    {
25
        $this->data = [
26
            'restrictionsCount' => $this->storageManager->getItemsCount(),
27
            'restrictions'      => $this->storageManager->fetchAllItems()
28
        ];
29
    }
30
31
    /**
32
     * @return array
33
     */
34
    public function getRestrictionsCount()
35
    {
36
        return $this->data['restrictionsCount'];
37
    }
38
39
    /**
40
     * @return array
41
     */
42
    public function getRestrictions()
43
    {
44
        return $this->data['restrictions'];
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getName()
51
    {
52
        return 'nv.request_limit.restrictions_collector';
53
    }
54
55
    /**
56
     * @param StorageManager $manager
57
     */
58
    public function setStorageManager(StorageManager $manager)
59
    {
60
        $this->storageManager = $manager;
61
    }
62
63
    /**
64
     * @return array
65
     */
66
    function __sleep()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
67
    {
68
        return ['data'];
69
    }
70
}
71