System::compareBEditaApiVersion()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * BEdita, API-first content management framework
6
 * Copyright 2024 Chialab Srl
7
 *
8
 * This file is part of BEdita: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published
10
 * by the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
14
 */
15
16
namespace App\Utility;
17
18
class System
19
{
20
    /**
21
     * Compare BEdita API version
22
     *
23
     * @param string $actual Actual API version
24
     * @param string $expected Expected API version
25
     * @return bool
26
     */
27
    public static function compareBEditaApiVersion(string $actual, string $expected): bool
28
    {
29
        $apiMajor = substr($actual, 0, strpos($actual, '.'));
30
        $requiredApiMajor = substr($expected, 0, strpos($expected, '.'));
31
32
        return $apiMajor === $requiredApiMajor && version_compare($actual, $expected) >= 0;
33
    }
34
}
35