Passed
Push — master ( da7684...88d58f )
by BruceScrutinizer
02:01
created

ComposerJson::detectComposerJsonDirectory()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 4
eloc 14
c 1
b 1
f 1
nc 4
nop 0
dl 0
loc 25
rs 9.7998

1 Method

Rating   Name   Duplication   Size   Complexity  
A ComposerJson::getPsr4Ns() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace NamespaceProtector\Scanner;
5
6
use NamespaceProtector\Common\PathInterface;
7
use NamespaceProtector\Exception\NamespaceProtectorExceptionInterface;
8
use Webmozart\Assert\Assert;
9
10
final class ComposerJson implements ComposerJsonInterface
11
{
12
    public const FILE_NAME = 'composer.json';
13
    public const NAME_PROJECT_IN_COMPOSER = 'brucegithub/namespace-protector';
14
15
    /** @var string */
16
    private $fileSystemPathComposerJson;
17
18
    /** @var array<string> */
19
    private $psr4Ns;
20
21
    public function __construct(PathInterface $fileSystemPathComposerJson)
22
    {
23
        $this->fileSystemPathComposerJson = $fileSystemPathComposerJson->get()
24
            . DIRECTORY_SEPARATOR
25
            . self::FILE_NAME;
26
27
        Assert::readable($this->fileSystemPathComposerJson, NamespaceProtectorExceptionInterface::MSG_PLAIN_ERROR_COMPOSER_JSON_NOT_READABLE);
28
    }
29
30
    public function load(): void
31
    {
32
        $content = \safe\file_get_contents($this->fileSystemPathComposerJson);
33
34
        $data = \safe\json_decode($content, true);
35
36
        $this->psr4Ns = $data['autoload']['psr-4'];
37
    }
38
39
    /** @return  array<string> */
40
    public function getPsr4Ns(): array
41
    {
42
        return $this->psr4Ns;
43
    }
44
}
45