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 Symfony\Component\HttpFoundation\Request; |
||
9 | use Symfony\Component\HttpFoundation\Response; |
||
10 | |||
11 | class BundleVersionDataCollector extends AbstractDataCollector |
||
12 | { |
||
13 | /** @var VersionChecker */ |
||
14 | private $versionChecker; |
||
15 | |||
16 | /** @var Cache */ |
||
17 | private $cache; |
||
18 | |||
19 | public function __construct(VersionChecker $versionChecker, /*Logger $logger,*/ /* Cache */ $cache) |
||
20 | { |
||
21 | $this->versionChecker = $versionChecker; |
||
22 | |||
23 | View Code Duplication | if (\func_num_args() > 2) { |
|
0 ignored issues
–
show
|
|||
24 | @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
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
|
|||
25 | |||
26 | $this->cache = func_get_arg(2); |
||
27 | |||
28 | return; |
||
29 | } |
||
30 | |||
31 | $this->cache = $cache; |
||
32 | } |
||
33 | |||
34 | public function getAccessRoles() |
||
35 | { |
||
36 | return ['ROLE_SUPER_ADMIN']; |
||
37 | } |
||
38 | |||
39 | public function collectData() |
||
40 | { |
||
41 | $this->versionChecker->periodicallyCheck(); |
||
42 | |||
43 | $data = $this->cache->fetch('version_check'); |
||
44 | |||
45 | return [ |
||
46 | 'data' => $data, |
||
47 | ]; |
||
48 | } |
||
49 | |||
50 | public function collect(Request $request, Response $response, \Exception $exception = null) |
||
51 | { |
||
52 | if (!$this->isEnabled()) { |
||
53 | $this->data = []; |
||
54 | } else { |
||
55 | $this->data = $this->collectData(); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Gets the data for template |
||
61 | * |
||
62 | * @return array The request events |
||
63 | */ |
||
64 | public function getTemplateData() |
||
65 | { |
||
66 | return $this->data; |
||
67 | } |
||
68 | |||
69 | public function getName() |
||
70 | { |
||
71 | return 'kuma_bundle_versions'; |
||
72 | } |
||
73 | |||
74 | public function isEnabled() |
||
75 | { |
||
76 | return $this->versionChecker->isEnabled(); |
||
77 | } |
||
78 | |||
79 | public function reset() |
||
80 | { |
||
81 | $this->data = []; |
||
82 | } |
||
83 | } |
||
84 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.