Passed
Push — master ( 85f9d4...f6c128 )
by Jakub
12:52
created

findVendorDirectory()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.016

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 9
c 3
b 1
f 0
dl 0
loc 14
rs 9.9666
ccs 9
cts 10
cp 0.9
cc 4
nc 1
nop 0
crap 4.016
1
<?php
2
3
declare(strict_types=1);
4
5
function findVendorDirectory(): string
6
{
7 1
    $recursionLimit = 10;
8 1
    $findVendor = function ($dirName = "vendor/bin", $dir = __DIR__) use (&$findVendor, &$recursionLimit) {
9 1
        if (!$recursionLimit--) {
10
            throw new Exception("Cannot find vendor directory.");
11
        }
12 1
        $found = $dir . "/$dirName";
13 1
        if (is_dir($found) || is_file($found)) {
14 1
            return dirname($found);
15
        }
16 1
        return $findVendor($dirName, dirname($dir));
17 1
    };
18 1
    return $findVendor();
19
}
20