These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\AdminBundle\Toolbar; |
||
4 | |||
5 | use Doctrine\Common\Cache\Cache; |
||
6 | use Kunstmaan\AdminBundle\Helper\Toolbar\AbstractDataCollector; |
||
7 | use Kunstmaan\AdminBundle\Helper\VersionCheck\VersionChecker; |
||
8 | use Monolog\Logger; |
||
9 | use Symfony\Component\HttpFoundation\Request; |
||
10 | use Symfony\Component\HttpFoundation\Response; |
||
11 | |||
12 | class BundleVersionDataCollector extends AbstractDataCollector |
||
13 | { |
||
14 | /** @var VersionChecker */ |
||
15 | private $versionChecker; |
||
16 | |||
17 | /** @var Cache */ |
||
18 | private $cache; |
||
19 | |||
20 | public function __construct(VersionChecker $versionChecker, /*Logger $logger,*/ /* Cache */ $cache) |
||
21 | { |
||
22 | $this->versionChecker = $versionChecker; |
||
23 | |||
24 | View Code Duplication | if (func_num_args() > 2) { |
|
25 | @trigger_error(sprintf('Passing the "logger" service as the second argument in "%s" is deprecated in KunstmaanAdminBundle 5.1 and will be removed in KunstmaanAdminBundle 6.0. Remove the "logger" argument from your service definition.', __METHOD__), E_USER_DEPRECATED); |
||
0 ignored issues
–
show
|
|||
26 | |||
27 | $this->cache = func_get_arg(2); |
||
28 | |||
29 | return; |
||
30 | } |
||
31 | |||
32 | $this->cache = $cache; |
||
33 | } |
||
34 | |||
35 | public function getAccessRoles() |
||
36 | { |
||
37 | return ['ROLE_SUPER_ADMIN']; |
||
38 | } |
||
39 | |||
40 | public function collectData() |
||
41 | { |
||
42 | $this->versionChecker->periodicallyCheck(); |
||
43 | |||
44 | $data = $this->cache->fetch('version_check'); |
||
45 | |||
46 | return [ |
||
47 | 'data' => $data, |
||
48 | ]; |
||
49 | } |
||
50 | |||
51 | public function collect(Request $request, Response $response, \Exception $exception = null) |
||
52 | { |
||
53 | if (!$this->isEnabled()) { |
||
54 | $this->data = []; |
||
55 | } else { |
||
56 | $this->data = $this->collectData(); |
||
57 | } |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Gets the data for template |
||
62 | * |
||
63 | * @return array The request events |
||
64 | */ |
||
65 | public function getTemplateData() |
||
66 | { |
||
67 | return $this->data; |
||
68 | } |
||
69 | |||
70 | public function getName() |
||
71 | { |
||
72 | return 'kuma_bundle_versions'; |
||
73 | } |
||
74 | |||
75 | public function isEnabled() |
||
76 | { |
||
77 | return $this->versionChecker->isEnabled(); |
||
78 | } |
||
79 | |||
80 | public function reset() |
||
81 | { |
||
82 | $this->data = []; |
||
83 | } |
||
84 | } |
||
85 |
If you suppress an error, we recommend checking for the error condition explicitly: