FabricaRequirements::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of Fabrica.
5
 *
6
 * (c) Alexandre Salomé <[email protected]>
7
 * (c) Julien DIDIER <[email protected]>
8
 *
9
 * This source file is subject to the GPL license that is bundled
10
 * with this source code in the file LICENSE.
11
 */
12
13
namespace Fabrica\Component\Requirements;
14
15
/**
16
 * @author Alexandre Salomé <[email protected]>
17
 */
18
class FabricaRequirements extends RequirementCollection
19
{
20
    public function __construct()
21
    {
22
        // PHP Version
23
        $this->addRequirement(
24
            version_compare(PHP_VERSION, '5.3.7', '>='),
25
            'Your PHP must be greater than 5.3.7 ('.PHP_VERSION.' installed)'
26
        );
27
28
        // Git command
29
        list($gitInstalled, $gitVersion) = $this->findGit();
30
        $this->addRequirement(
31
            $gitInstalled && version_compare($gitVersion, '1.7', '>='),
32
            'Your git must be greater than 1.7 ('.$gitVersion.' installed)'
33
        );
34
    }
35
36
    protected function findGit()
37
    {
38
        $proc = proc_open(
39
            'git --version',
40
            array(
41
                0 => array('pipe', 'r'),
42
                1 => array('pipe', 'w'),
43
                2 => array('pipe', 'w')
44
            ), $pipes
45
        );
46
47
        $res = preg_match('/^git version ([0-9\.]+)(.+)?\n$/', stream_get_contents($pipes[1]), $vars);
48
        $rtn = proc_close($proc);
0 ignored issues
show
Unused Code introduced by
$rtn is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
49
        if (!$res) {
50
            return array(false, 'none');
51
        }
52
        $version = $vars[1];
53
54
        return array(true, $version);
55
    }
56
}
57