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

ComposerJson   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 1
Metric Value
eloc 13
dl 0
loc 33
rs 10
c 4
b 1
f 1
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getPsr4Ns() 0 3 1
A load() 0 7 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