Passed
Push — v3 ( dc9fae...2f2fc6 )
by Andrew
18:54 queued 11:52
created

src/helpers/Version.php (1 issue)

Severity
1
<?php
2
/**
3
 * Retour plugin for Craft CMS 3.x
4
 *
5
 * Retour allows you to intelligently redirect legacy URLs, so that you don't
6
 * lose SEO value when rebuilding & restructuring a website
7
 *
8
 * @link      https://nystudio107.com/
9
 * @copyright Copyright (c) 2021 nystudio107
10
 */
11
12
namespace nystudio107\retour\helpers;
13
14
use \Composer\InstalledVersions;
15
use \Composer\Semver\Semver;
16
17
/**
18
 * @author    nystudio107
19
 * @package   Retour
20
 * @since     3.1.48
21
 */
22
class Version
23
{
24
    // Constants
25
    // =========================================================================
26
27
    const LEAGUE_CSV_PACKAGE = 'league/csv';
28
29
    // Public Static Methods
30
    // =========================================================================
31
32
    /**
33
     * Return the API version for `league/csv` package
34
     *
35
     * @return int API version (or 0 for not installed)
36
     */
37
    public static function getLeagueCsvVersion(): int
38
    {
39
        $version = 0;
40
        $installedVersion = null;
0 ignored issues
show
The assignment to $installedVersion is dead and can be removed.
Loading history...
41
        try {
42
            $installedVersion = InstalledVersions::getVersion(self::LEAGUE_CSV_PACKAGE);
43
        } catch (\Throwable $e) {
44
            // That's fine
45
        }
46
        if ($installedVersion) {
47
            if (Semver::satisfies($installedVersion, '^8.0.0')) {
48
                $version = 8;
49
            }
50
            if (Semver::satisfies($installedVersion, '^9.0.0')) {
51
                $version = 9;
52
            }
53
        }
54
55
        return $version;
56
    }
57
}
58