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

ComposerFile   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 11
dl 0
loc 30
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createEmpty() 0 3 1
A __construct() 0 10 2
A getPath() 0 3 1
A getDecodedContents() 0 3 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 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