ExecutableTester   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 7 4
1
<?php
2
namespace Nubs\Which;
3
4
use Icecave\Isolator\Isolator;
5
6
/**
7
 * Tests paths to see if they are executable.
8
 */
9
class ExecutableTester
10
{
11
    /** @type \Icecave\Isolator\Isolator The DIC for global functions. */
12
    private $_isolator;
13
14
    /**
15
     * Initialize the executable tester.
16
     *
17
     * @param \Icecave\Isolator\Isolator The DIC for global functions.
18
     */
19
    public function __construct(Isolator $isolator = null)
20
    {
21
        $this->_isolator = $isolator;
22
    }
23
24
    /**
25
     * Tests the given path to see if it is an executable command.
26
     *
27
     * @param string $path The path to a command to test.
28
     * @return boolean True if the path is an executable command, false
29
     *     otherwise.
30
     */
31
    public function __invoke($path)
32
    {
33
        $isExecutable = $this->_isolator ? $this->_isolator->is_executable($path) : is_executable($path);
34
        $isDir = $this->_isolator ? $this->_isolator->is_dir($path) : is_dir($path);
35
36
        return $isExecutable && !$isDir;
37
    }
38
}
39