SourceUrl   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 50
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
C __invoke() 0 31 7
1
<?php
2
3
namespace Knp\MegaMAN\Filter;
4
5
use Knp\MegaMAN\Filter;
6
7
class SourceUrl 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
            $definition['url'] = '';
36
37
            foreach ($json as $installed) {
38
                if ($installed['name'] === $definition['package']) {
39
                    if (false === array_key_exists('source', $installed)) {
40
                        continue;
41
                    }
42
43
                    if (false === array_key_exists('url', $installed['source'])) {
44
                        continue;
45
                    }
46
47
                    $definition['url'] = $installed['source']['url'];
48
                }
49
            }
50
51
            $result[] = $definition;
52
        }
53
54
        return $result;
55
    }
56
}
57