VersionInstalled::__invoke()   B
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
nc 3
nop 1
1
<?php
2
3
namespace Knp\MegaMAN\Filter;
4
5
use Knp\MegaMAN\Filter;
6
7
class VersionInstalled implements Filter
8
{
9
    /**
10
     * @var string
11
     */
12
    private $installed;
13
14
    /**
15
     * @param string $installed
16
     */
17
    public function __construct($installed)
18
    {
19
        $this->installed = $installed;
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function __invoke(array $array)
26
    {
27
        $result = [];
28
        $json   = json_decode(file_get_contents($this->installed), true);
29
30
        foreach ($array as $definition) {
31
            if (false === array_key_exists('package', $definition)) {
32
                continue;
33
            }
34
35
            foreach ($json as $installed) {
36
                if ($installed['name'] === $definition['package']) {
37
                    $definition['version'] = $installed['version'];
38
                    $result[]              = $definition;
39
                }
40
            }
41
        }
42
43
        return $result;
44
    }
45
}
46