Passed
Pull Request — master (#370)
by Théo
02:22
created

ComposerFiles   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 17
dl 0
loc 50
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstalledJson() 0 3 1
A getComposerLock() 0 3 1
A createEmpty() 0 6 1
A getPaths() 0 7 1
A getComposerJson() 0 3 1
A __construct() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the box project.
7
 *
8
 * (c) Kevin Herrera <[email protected]>
9
 *     Théo Fidry <[email protected]>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14
15
namespace KevinGH\Box\Composer;
16
17
use function array_filter;
18
use function array_map;
19
20
final class ComposerFiles
21
{
22
    private $composerJson;
23
    private $composerLock;
24
    private $installedJson;
25
26
    public static function createEmpty(): self
27
    {
28
        return new self(
29
            ComposerFile::createEmpty(),
30
            ComposerFile::createEmpty(),
31
            ComposerFile::createEmpty()
32
        );
33
    }
34
35
    public function __construct(
36
        ComposerFile $composerJson,
37
        ComposerFile $composerLock,
38
        ComposerFile $installedJson
39
    ) {
40
        $this->composerJson = $composerJson;
41
        $this->composerLock = $composerLock;
42
        $this->installedJson = $installedJson;
43
    }
44
45
    public function getComposerJson(): ComposerFile
46
    {
47
        return $this->composerJson;
48
    }
49
50
    public function getComposerLock(): ComposerFile
51
    {
52
        return $this->composerLock;
53
    }
54
55
    public function getInstalledJson(): ComposerFile
56
    {
57
        return $this->installedJson;
58
    }
59
60
    /**
61
     * @return string[]
62
     */
63
    public function getPaths(): array
64
    {
65
        return array_filter(array_map(
66
            static function (ComposerFile $file): ?string {
67
                return $file->getPath();
68
            },
69
            [$this->composerJson, $this->composerLock, $this->installedJson]
70
        ));
71
    }
72
}
73