Passed
Push — master ( 7ca88e...9f8c4e )
by Mariano
04:25
created

Version   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 22
ccs 9
cts 9
cp 1
rs 10
c 2
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A ensureVersionIsCorrect() 0 4 2
A __construct() 0 4 1
A asString() 0 3 1
1
<?php
2
/**
3
 * This file is part of Phiremock.
4
 *
5
 * Phiremock is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Lesser General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * Phiremock is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with Phiremock.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace Mcustiel\Phiremock\Domain;
20
21
class Version
22
{
23
    private const VALID_VERSIONS = ['1', '2'];
24
25
    /** @var string */
26
    private $version;
27
28 48
    public function __construct(string $version)
29
    {
30 48
        $this->ensureVersionIsCorrect($version);
31 30
        $this->version = $version;
32 30
    }
33
34 30
    public function asString(): string
35
    {
36 30
        return $this->version;
37
    }
38
39 48
    private function ensureVersionIsCorrect(string $version): void
40
    {
41 48
        if (!\in_array($version, self::VALID_VERSIONS, true)) {
42 18
            throw new \InvalidArgumentException(sprintf('Invalid version: %s', $version));
43
        }
44 30
    }
45
}
46