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

ComposerFile::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
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 Assert\Assertion;
18
19
final class ComposerFile
20
{
21
    private $path;
22
    private $contents;
23
24
    public static function createEmpty(): self
25
    {
26
        return new self(null, []);
27
    }
28
29
    public function __construct(?string $path, array $contents)
30
    {
31
        Assertion::nullOrNotEmpty($path);
32
33
        if (null === $path) {
34
            Assertion::same([], $contents);
35
        }
36
37
        $this->path = $path;
38
        $this->contents = $contents;
39
    }
40
41
    public function getPath(): ?string
42
    {
43
        return $this->path;
44
    }
45
46
    public function getDecodedContents(): array
47
    {
48
        return $this->contents;
49
    }
50
}
51