CliFunctionChecker::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace RMiller\BehatSpec\Extension\PhpSpecRunExtension\Process\CommandRunner;
4
5
use RMiller\BehatSpec\Extension\PhpSpecRunExtension\Process\CachingExecutableFinder;
6
7
class CliFunctionChecker
8
{
9
    /**
10
     * @var \RMiller\BehatSpec\Extension\PhpSpecRunExtension\Process\CachingExecutableFinder
11
     */
12
    private $executableFinder;
13
14
    /**
15
     * @param \RMiller\BehatSpec\Extension\PhpSpecRunExtension\Process\CachingExecutableFinder $executableFinder
16
     */
17
    public function __construct(CachingExecutableFinder $executableFinder)
18
    {
19
        $this->executableFinder = $executableFinder;
20
    }
21
22
    /**
23
     * @param string $function
24
     *
25
     * @return bool
26
     */
27
    public function functionCanBeUsed($function)
28
    {
29
        return (php_sapi_name() == 'cli')
30
            && $this->executableFinder->getExecutablePath()
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->executableFinder->getExecutablePath() of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
31
            && function_exists($function);
32
    }
33
}
34