Completed
Push — master ( da86b5...1bc0f1 )
by Sander
19:35 queued 01:28
created

BundleVersionDataCollector   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 73
Duplicated Lines 9.59 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 7
loc 73
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 14 2
A getAccessRoles() 0 4 1
A collectData() 0 10 1
A collect() 0 8 2
A getTemplateData() 0 4 1
A getName() 0 4 1
A isEnabled() 0 4 1
A reset() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
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
Security Best Practice introduced by
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...
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