VersionInstalled   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B __invoke() 0 20 5
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