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 ( 9afe37...f3ad9d )
by joseph
9s
created

Helper::getProjectRootDirectory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
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 2
        if (null === self::$projectRootDirectory) {
22 1
            $reflection                 = new \ReflectionClass(ClassLoader::class);
23 1
            self::$projectRootDirectory = \dirname($reflection->getFileName(), 3);
24
        }
25
26 2
        return self::$projectRootDirectory;
27
    }
28
29
    /**
30
     * @param string|null $path
31
     *
32
     * @return array
33
     * @throws \Exception
34
     * @SuppressWarnings(PHPMD.StaticAccess)
35
     */
36 2
    public static function getComposerJsonDecoded(string $path = null): array
37
    {
38 2
        $path    = $path ?? self::getProjectRootDirectory().'/composer.json';
39 2
        $decoded = \json_decode(\file_get_contents($path), true);
40 2
        if (JSON_ERROR_NONE !== \json_last_error()) {
41 1
            throw new \RuntimeException('Failed loading composer.json: '.\json_last_error_msg());
42
        }
43
44 1
        return $decoded;
45
    }
46
}
47