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   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 38
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getComposerJsonDecoded() 0 9 2
A getProjectRootDirectory() 0 8 2
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