Total Complexity | 5 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Coverage | 56.25% |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
7 | class Helper |
||
8 | { |
||
9 | private static $projectRootDirectory; |
||
10 | |||
11 | /** |
||
12 | * Get the absolute path to the root of the current project |
||
13 | * |
||
14 | * It does this by working from the Composer autoloader which we know will be in a certain place in `vendor` |
||
15 | * |
||
16 | * @return string |
||
17 | * @throws \Exception |
||
18 | */ |
||
19 | 1 | public static function getProjectRootDirectory(): string |
|
20 | { |
||
21 | try { |
||
22 | 1 | if (null === self::$projectRootDirectory) { |
|
23 | $reflection = new \ReflectionClass(ClassLoader::class); |
||
24 | self::$projectRootDirectory = \dirname($reflection->getFileName(), 3); |
||
25 | } |
||
26 | |||
27 | 1 | return self::$projectRootDirectory; |
|
28 | } catch (\Exception $e) { |
||
29 | throw new \Exception( |
||
30 | 'Exception in '.__METHOD__.': '.$e->getMessage(), |
||
31 | $e->getCode(), |
||
32 | $e |
||
33 | ); |
||
34 | } |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @param string|null $path |
||
39 | * |
||
40 | * @return array |
||
41 | * @throws \Exception |
||
42 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
43 | */ |
||
44 | 2 | public static function getComposerJsonDecoded(string $path = null): array |
|
53 | } |
||
54 | } |
||
55 |