Completed
Push — master ( 5f4179...916f6e )
by Richard
11s
created

CliFunctionChecker::functionCanBeUsed()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 4

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
dl 6
loc 6
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 1
1
<?php
2
3
namespace RMiller\BehatSpec\Extension\PhpSpecRunExtension\Process\CommandRunner;
4
5
use RMiller\BehatSpec\Extension\PhpSpecRunExtension\Process\CachingExecutableFinder;
6
7 View Code Duplication
class CliFunctionChecker
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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