DevDependency::__invoke()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 13

Duplication

Lines 3
Ratio 12.5 %

Importance

Changes 0
Metric Value
dl 3
loc 24
rs 8.6845
c 0
b 0
f 0
cc 4
eloc 13
nc 4
nop 1
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