Completed
Push — master ( 5c8a13...04755b )
by Novikov
01:34
created

RestrictionsCollector::collect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 5
rs 9.4285
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
    private $data;
13
14
    /** @var StorageManager $storageManager */
15
    private $storageManager;
16
17
    /**
18
     * @inheritdoc
19
     */
20
    public function collect(Request $request, Response $response, \Exception $exception = null)
21
    {
22
        $this->data = [
23
            'restrictionsCount' => $this->storageManager->getItemsCount(),
24
            'restrictions'      => $this->storageManager->fetchAllItems()
25
        ];
26
    }
27
28
    /**
29
     * @return array
30
     */
31
    public function getRestrictionsCount()
32
    {
33
        return $this->data['restrictionsCount'];
34
    }
35
36
    /**
37
     * @return array
38
     */
39
    public function getRestrictions()
40
    {
41
        return $this->data['restrictions'];
42
    }
43
44
    public function getName()
45
    {
46
        return 'nv.request_limit.restrictions_collector';
47
    }
48
49
    /**
50
     * @param StorageManager $manager
51
     */
52
    public function setStorageManager(StorageManager $manager)
53
    {
54
        $this->storageManager = $manager;
55
    }
56
}
57