Passed
Push — master ( 23a781...1a23d8 )
by Hannes
03:13 queued 01:43
created

Package::validateVersion()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace inroutephp\inroute;
6
7
use inroutephp\inroute\Runtime\Exception\CompatibilityException;
8
9
final class Package
10
{
11
    /**
12
     * Current package version number
13
     */
14
    const VERSION = "1.0.0-beta6";
15
16
    /**
17
     * The lowest version number this runtime is compatible with
18
     */
19
    private const LOWEST_SUPPORTED_VERSION = '1.0.0-beta6';
20
21
    /**
22
     * The lowest version number this runtime is not compatible with
23
     */
24
    private const LOWEST_UNSUPPORTED_VERSION = '2';
25
26
    /**
27
     * Error message template
28
     */
29
    private const ERROR_MSG = 'Unable to read router compiled with inroute version %s using runtime version %s.';
30
31
    /**
32
     * Validate that version number is supported by the runtime
33
     */
34
    public static function validateVersion(string $version): void
35
    {
36
        if (version_compare($version, self::LOWEST_SUPPORTED_VERSION, '<')) {
37
            throw new CompatibilityException(sprintf(self::ERROR_MSG, $version, self::VERSION));
38
        }
39
40
        if (version_compare($version, self::LOWEST_UNSUPPORTED_VERSION, '>=')) {
41
            throw new CompatibilityException(sprintf(self::ERROR_MSG, $version, self::VERSION));
42
        }
43
    }
44
}
45