GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 79a1c3...b48fec )
by joseph
13s
created

Helper::getProjectRootDirectory()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.125

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 4
nop 0
dl 0
loc 14
ccs 5
cts 10
cp 0.5
crap 4.125
rs 9.4285
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\PHPQA;
4
5
use Composer\Autoload\ClassLoader;
6
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 2
    public static function getProjectRootDirectory(): string
20
    {
21
        try {
22 2
            if (null === self::$projectRootDirectory) {
23 1
                $reflection                 = new \ReflectionClass(ClassLoader::class);
24 1
                self::$projectRootDirectory = \dirname($reflection->getFileName(), 3);
25
            }
26
27 2
            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 5
    public static function getComposerJsonDecoded(string $path = null): array
45
    {
46 5
        $path    = $path ?? self::getProjectRootDirectory().'/composer.json';
47 5
        $decoded = \json_decode(\file_get_contents($path), true);
48 5
        if (JSON_ERROR_NONE !== \json_last_error()) {
49 1
            throw new \RuntimeException('Failed loading composer.json: '.\json_last_error_msg());
50
        }
51
52 4
        return $decoded;
53
    }
54
}
55