RestrictionsCollector::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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
    public function __sleep()
67
    {
68
        return ['data'];
69
    }
70
}
71