Test Failed
Push — master ( fe7900...79d767 )
by Attila
11:12
created

ManifestFile   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 31
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A read() 0 9 2
A getVersion() 0 3 1
A __construct() 0 4 1
A getName() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Contains the Module ManifestFile class.
7
 *
8
 * @copyright   Copyright (c) 2016 Attila Fulop
9
 * @author      Attila Fulop
10
 * @license     MIT
11
 * @since       2016-08-14
12
 *
13
 */
14
15
namespace Konekt\Concord\Module;
16
17
use RuntimeException;
18
19
final class ManifestFile
20
{
21
    private string $name;
22
23
    private ?string $version;
24
25
    public static function read(string $filePath): ManifestFile
26
    {
27
        if (!is_readable($filePath)) {
28
            throw new RuntimeException("The module manifest file `$filePath` can not be read");
29
        }
30
31
        $data = include($filePath);
32
33
        return new ManifestFile($data['name'] ?? 'N/A', $data['version'] ?? null);
34
    }
35
36
    public function getName(): string
37
    {
38
        return $this->name;
39
    }
40
41
    public function getVersion(): ?string
42
    {
43
        return $this->version;
44
    }
45
46
    private function __construct(string $name, ?string $version)
47
    {
48
        $this->name = $name;
49
        $this->version = $version;
50
    }
51
}
52