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

ComposerJson::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 3
b 0
f 0
nc 1
nop 1
dl 0
loc 7
rs 10
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