ManifestFile::getVersion()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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
    private function __construct(string $name, ?string $version)
26
    {
27
        $this->name = $name;
28
        $this->version = $version;
29
    }
30
31
    public static function read(string $filePath): ManifestFile
32
    {
33
        if (!is_readable($filePath)) {
34
            throw new RuntimeException("The module manifest file `$filePath` can not be read");
35
        }
36
37
        $data = include($filePath);
38
39
        return new ManifestFile($data['name'] ?? 'N/A', $data['version'] ?? null);
40
    }
41
42
    public function getName(): string
43
    {
44
        return $this->name;
45
    }
46
47
    public function getVersion(): ?string
48
    {
49
        return $this->version;
50
    }
51
}
52