Passed
Push — master ( b6b0b7...148695 )
by Gabriel
03:18
created

Path   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 10
c 1
b 0
f 1
dl 0
loc 21
rs 10
ccs 9
cts 10
cp 0.9

1 Method

Rating   Name   Duplication   Size   Complexity  
A basePath() 0 14 3
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