Path::basePath()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.009

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
c 1
b 0
f 1
dl 0
loc 14
rs 9.9666
ccs 9
cts 10
cp 0.9
cc 3
nc 3
nop 1
crap 3.009
1
<?php
2
3
namespace Nip\Controllers\Utility;
4
5
/**
6
 * Class Path
7
 * @package Nip\Controllers\Utility
8
 */
9
class Path
10
{
11
    /**
12
     * @param $controller
13
     * @return bool|string
14
     * @noinspection PhpDocMissingThrowsInspection
15
     */
16 5
    public static function basePath($controller)
17
    {
18
        /** @noinspection PhpUnhandledExceptionInspection */
19 5
        $reflection = new \ReflectionClass($controller);
20 5
        $path = dirname($reflection->getFileName());
21 5
        $parts = explode(DIRECTORY_SEPARATOR, $path);
22 5
        while (count($parts) > 1) {
23 5
            $lastPart = end($parts);
24 5
            if (strtolower($lastPart) == 'controllers') {
25 5
                return implode(DIRECTORY_SEPARATOR, $parts);
26
            }
27 3
            array_pop($parts);
28
        }
29
        return false;
30
    }
31
}
32