1 | <?php |
||
21 | class AdminCollector extends DataCollector |
||
22 | { |
||
23 | const TYPE_NOT_MANAGED = 'Not Managed'; |
||
24 | |||
25 | /** |
||
26 | * @var Collector |
||
27 | */ |
||
28 | private $collector; |
||
29 | |||
30 | public function collect(Request $request, Response $response, \Exception $exception = null) |
||
31 | { |
||
32 | $this->data = [ |
||
33 | DataCollection::DESTINATION_TOOLBAR => [], |
||
34 | DataCollection::DESTINATION_PROFILER => [], |
||
35 | ]; |
||
36 | |||
37 | $collectedData = $this->collector->getData(); |
||
38 | |||
39 | $hooks = 0; |
||
40 | |||
41 | foreach ($collectedData as $k => $dataCollection) { |
||
42 | $data = $dataCollection->getData(); |
||
43 | |||
44 | if (preg_replace('/\#[0-9]*\W/', '', $k) === 'Managed classes') { |
||
45 | $this->addToProfiler($k, 'Managed classes', [ |
||
46 | 'display' => DataCollection::DESTINATION_TOOLBAR, // 'toolbar', 'profiler', 'both' |
||
|
|||
47 | 'class' => count($data), |
||
48 | ]); |
||
49 | } |
||
50 | |||
51 | if (preg_replace('/^\#[0-9]*\W/', '', $k) === 'Hook') { |
||
52 | $hooks++; |
||
53 | } |
||
54 | |||
55 | if ($data instanceof BaseGroupedMapper || $data instanceof BaseMapper) { |
||
56 | $entity = $data->getAdmin()->getClass(); |
||
57 | $admin = $data->getAdmin(); |
||
58 | |||
59 | $this->addToProfiler($k, 'entity', [ |
||
60 | 'display' => DataCollection::DESTINATION_PROFILER, |
||
61 | 'class' => $entity, |
||
62 | 'file' => $this->getClassLink($entity), |
||
63 | ]); |
||
64 | |||
65 | $this->addToProfiler($k, 'admin', [ |
||
66 | 'display' => DataCollection::DESTINATION_PROFILER, |
||
67 | 'class' => get_class($admin), |
||
68 | 'file' => $this->getClassLink(get_class($admin)), |
||
69 | ]); |
||
70 | |||
71 | // Not really usefull because other type of mapper have not been tested |
||
72 | // |
||
73 | // $this->addToProfiler($k, 'mapper', [ |
||
74 | // 'display' => DataCollection::DESTINATION_PROFILER, |
||
75 | // 'class' => get_class($data), |
||
76 | // 'file' => $this->getClassLink(get_class($data)), |
||
77 | // ]); |
||
78 | |||
79 | $this->addToProfiler($k, 'form tabs / groups', [ |
||
80 | 'display' => DataCollection::DESTINATION_PROFILER, |
||
81 | 'class' => count($admin->getFormTabs()) . ' / ' . count($admin->getFormGroups()), |
||
82 | ]); |
||
83 | |||
84 | $this->addToProfiler($k, 'form', [ |
||
85 | 'display' => DataCollection::DESTINATION_PROFILER, |
||
86 | 'Tabs and Groups' => [ |
||
87 | 'tabs' => $admin->getFormTabs(), |
||
88 | 'groups' => $admin->getFormGroups(), |
||
89 | ], |
||
90 | ]); |
||
91 | |||
92 | $this->addToProfiler($k, 'show tabs / groups', [ |
||
93 | 'display' => DataCollection::DESTINATION_PROFILER, |
||
94 | 'class' => count($admin->getShowTabs()) . ' / ' . count($admin->getShowGroups()), |
||
95 | ]); |
||
96 | |||
97 | $this->addToProfiler($k, 'show', [ |
||
98 | 'display' => DataCollection::DESTINATION_PROFILER, |
||
99 | 'Tabs and Groups' => [ |
||
100 | 'tabs' => $admin->getShowTabs(), |
||
101 | 'groups' => $admin->getShowGroups(), |
||
102 | ], |
||
103 | ]); |
||
104 | } else { |
||
105 | $this->addToProfiler($k, $dataCollection->getName(), $dataCollection); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | $this->addToProfiler('Hook registered', 'Hooks', [ |
||
110 | 'display' => DataCollection::DESTINATION_TOOLBAR, // 'toolbar', 'profiler', 'both' |
||
111 | 'class' => $hooks, |
||
112 | ]); |
||
113 | } |
||
114 | |||
115 | public function getData($name = null) |
||
127 | |||
128 | public function getName() |
||
132 | |||
133 | /** |
||
134 | * @return Collector |
||
135 | */ |
||
136 | public function getCollector() |
||
140 | |||
141 | /** |
||
142 | * @param Collector collector |
||
143 | * |
||
144 | * @return self |
||
145 | */ |
||
146 | public function setCollector(Collector $collector) |
||
152 | |||
153 | private function getClassLink($class) |
||
159 | |||
160 | private function addToProfiler($rootKey, $key, $data) |
||
179 | } |
||
180 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.