DirectDependency::__invoke()   B
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 28
Code Lines 15

Duplication

Lines 3
Ratio 10.71 %

Importance

Changes 0
Metric Value
dl 3
loc 28
rs 8.439
c 0
b 0
f 0
cc 5
eloc 15
nc 6
nop 1
1
<?php
2
3
namespace Knp\MegaMAN\Filter;
4
5
use Knp\MegaMAN\Filter;
6
7
class DirectDependency 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
            if (true === array_key_exists('require', $json)) {
38
                $deps = array_merge($deps, $json['require']);
39
            }
40
41 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...
42
                $deps = array_merge($deps, $json['require-dev']);
43
            }
44
45
            $package              = $definition['package'];
46
            $definition['direct'] = array_key_exists($package, $deps);
47
48
            $result[] = $definition;
49
        }
50
51
        return $result;
52
    }
53
}
54