Completed
Push — master ( e8bfce...313e31 )
by Arnaud
13s queued 11s
created

AdminDataCollector::reset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

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
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace LAG\AdminBundle\Debug\DataCollector;
4
5
use Exception;
6
use LAG\AdminBundle\Configuration\ApplicationConfigurationStorage;
7
use LAG\AdminBundle\Menu\Provider\MenuProvider;
8
use LAG\AdminBundle\Resource\Registry\ResourceRegistryInterface;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
12
13
class AdminDataCollector extends DataCollector
14
{
15
    /**
16
     * @var ResourceRegistryInterface
17
     */
18
    private $registry;
19
20
    /**
21
     * @var ApplicationConfigurationStorage
22
     */
23
    private $storage;
24
25
    /**
26
     * @var MenuProvider
27
     */
28
    private $menuProvider;
29
30
    /**
31
     * AdminDataCollector constructor.
32
     */
33 2
    public function __construct(
34
        ResourceRegistryInterface $registry,
35
        ApplicationConfigurationStorage $storage,
36
        MenuProvider $menuProvider
37
    ) {
38 2
        $this->registry = $registry;
39 2
        $this->storage = $storage;
40 2
        $this->menuProvider = $menuProvider;
41 2
    }
42
43 2
    public function collect(Request $request, Response $response, Exception $exception = null)
44
    {
45
        $data = [
46 2
            'admins' => [],
47
            'application' => [],
48
            'menus' => [],
49
        ];
50
51 2
        foreach ($this->registry->all() as $resource) {
52 2
            $data['admins'][$resource->getName()] = [
53 2
                'entity_class' => $resource->getEntityClass(),
54 2
                'configuration' => $resource->getConfiguration(),
55
            ];
56
        }
57
58 2
        foreach ($this->storage->getConfiguration()->all() as $name => $parameter) {
59 2
            $data['application'][$name] = $parameter;
60
        }
61
62 2
        foreach ($this->menuProvider->all() as $menuName => $menu) {
63 2
            $data['menus'][$menuName] = [
64 2
                'attributes' => $menu->getAttributes(),
65 2
                'displayed' => $menu->isDisplayed(),
66
            ];
67
68 2
            foreach ($menu->getChildren() as $childName => $child) {
69 2
                $data['menus'][$menuName]['children'][$childName] = [
70 2
                    'attributes' => $child->getAttributes(),
71 2
                    'displayed' => $child->isDisplayed(),
72 2
                    'uri' => $child->getUri(),
73
                ];
74
            }
75
        }
76
77 2
        $data['application']['admin'] = $request->attributes->get('_admin');
78 2
        $data['application']['action'] = $request->attributes->get('_action');
79
80 2
        $this->data = $data;
81 2
    }
82
83
    /**
84
     * Returns the name of the collector.
85
     *
86
     * @return string The collector name
87
     */
88 2
    public function getName()
89
    {
90 2
        return 'admin.data_collector';
91
    }
92
93 2
    public function reset()
94
    {
95 2
        $this->data = [];
96 2
    }
97
98 2
    public function getData()
99
    {
100 2
        return $this->data;
101
    }
102
}
103