DevDependency   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 6.98 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 3
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B __invoke() 3 24 4

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 Knp\MegaMAN\Filter;
4
5
use Knp\MegaMAN\Filter;
6
7
class DevDependency implements Filter
8
{
9
    /**
10
     * @var string
11
     */
12
    private $composer;
13
14
    /**
15
     * @param string $composer
16
     */
17
    public function __construct($composer)
18
    {
19
        $this->composer = $composer;
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function __invoke(array $array)
26
    {
27
        $result = [];
28
29
        foreach ($array as $definition) {
30
            if (false === array_key_exists('package', $definition)) {
31
                continue;
32
            }
33
34
            $json = json_decode(file_get_contents($this->composer), true);
35
            $deps = [];
36
37 View Code Duplication
            if (true === array_key_exists('require-dev', $json)) {
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...
38
                $deps = array_merge($deps, $json['require-dev']);
39
            }
40
41
            $package           = $definition['package'];
42
            $definition['dev'] = array_key_exists($package, $deps);
43
44
            $result[] = $definition;
45
        }
46
47
        return $result;
48
    }
49
}
50