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

Version::ensureVersionIsCorrect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
c 1
b 0
f 0
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