PhpFinder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 39
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getPath() 0 13 3
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
namespace AnimeDb\Bundle\AppBundle\Service;
10
11
use Symfony\Component\Process\PhpExecutableFinder;
12
13
class PhpFinder
14
{
15
    /**
16
     * @var string
17
     */
18
    private $php_path;
19
20
    /**
21
     * @var PhpExecutableFinder
22
     */
23
    private $finder;
24
25
    /**
26
     * @param PhpExecutableFinder $finder
27
     */
28 2
    public function __construct(PhpExecutableFinder $finder)
29
    {
30 2
        $this->finder = $finder;
31 2
    }
32
33
    /**
34
     * @throws \RuntimeException
35
     *
36
     * @return string
37
     */
38 2
    public function getPath()
39
    {
40 2
        if (!$this->php_path) {
41 2
            if (!($this->php_path = $this->finder->find())) {
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->finder->find() can also be of type false. However, the property $php_path is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
42 1
                throw new \RuntimeException(
43 1
                    'The php executable could not be found, add it to your PATH environment variable and try again'
44
                );
45
            }
46 1
            $this->php_path = escapeshellarg($this->php_path);
47
        }
48
49 1
        return $this->php_path;
50
    }
51
}
52