ToolPathFinder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 41
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A find() 0 18 6
1
<?php
2
3
namespace PhpGitHooks\Infrastructure\Tool;
4
5
class ToolPathFinder
6
{
7
    const COMPOSER_VENDOR_DIR = '/../../../';
8
    const COMPOSER_INSTALLED_FILE = 'composer/installed.json';
9
10
    /** @var array */
11
    private $tools = array(
12
        'phpcs' => 'squizlabs/php_codesniffer',
13
        'php-cs-fixer' => 'friendsofphp/php-cs-fixer',
14
        'phpmd' => 'phpmd/phpmd',
15
        'phpunit' => 'phpunit/phpunit',
16
        'phpunit-randomizer' => 'fiunchinho/phpunit-randomizer',
17
        'jsonlint' => 'seld/jsonlint',
18
    );
19
    /** @var array */
20
    private $installedPackages = array();
21
22
    /**
23
     * @param string $tool
24
     *
25
     * @return string
26
     */
27
    public function find($tool)
28
    {
29
        if (isset($this->installedPackages[$this->tools[$tool]])) {
30
            $package = $this->installedPackages[$this->tools[$tool]];
31
            foreach ($package['bin'] as $bin) {
32
                if (preg_match("#${tool}$#", $bin)) {
33
                    return __DIR__.self::COMPOSER_VENDOR_DIR.$package['name'].DIRECTORY_SEPARATOR.$bin;
34
                }
35
            }
36
        }
37
38
        $binToolPath = 'bin'.DIRECTORY_SEPARATOR.$tool;
39
        if (file_exists($binToolPath) && is_file($binToolPath)) {
40
            return $binToolPath;
41
        }
42
43
        return 'vendor'.DIRECTORY_SEPARATOR.$binToolPath;
44
    }
45
}
46