LocalProject::__invoke()   B
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 3
eloc 15
nc 3
nop 1
1
<?php
2
3
namespace Knp\MegaMAN\Filter;
4
5
use Knp\MegaMAN\Filter;
6
7
class LocalProject implements Filter
8
{
9
    /**
10
     * @var string
11
     */
12
    private $readme;
13
14
    /**
15
     * @var string
16
     */
17
    private $composer;
18
19
    /**
20
     * @param string $readme
21
     * @param string $composer
22
     */
23
    public function __construct($readme, $composer)
24
    {
25
        $this->readme   = $readme;
26
        $this->composer = $composer;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function __invoke(array $array)
33
    {
34
        if (false === file_exists($this->readme)) {
35
            return $array;
36
        }
37
38
        if (false === file_exists($this->composer)) {
39
            return $array;
40
        }
41
42
        $json = json_decode(file_get_contents($this->composer), true);
43
44
        $array[] = [
45
            'composer' => $this->composer,
46
            'dev'      => null,
47
            'direct'   => null,
48
            'local'    => true,
49
            'package'  => $json['name'],
50
            'readme'   => $this->readme,
51
            'version'  => 'local',
52
        ];
53
54
        return $array;
55
    }
56
}
57