• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taobig / php-helper / 9809350785

05 Jul 2024 01:47PM UTC coverage: 95.238% (+0.2%) from 95.072%
9809350785

push

github

taobig
Update CI config

480 of 504 relevant lines covered (95.24%)

1.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/src/composer/Version.php
1
<?php
2

3

4
namespace taobig\helpers\composer;
5

6

7
class Version
8
{
9

10
    public const PACKAGE_ALL = 'package_all';
11
    public const PACKAGE_DEV = 'package_dev';
12

13
    /**
14
     * @Deprecated
15
     * @see PACKAGE
16
     */
17
    public const PACKAGE_PROD = self::PACKAGE;
18
    public const PACKAGE = 'package';
19

20
    /**
21
     * @param string $composerLockFile
22
     * @param string $packageName
23
     * @param string $floorVersion eg. "1.2.3", NOT "v1.2.3"
24
     * @param string $packageMode 'all':package and package-dev; 'package'; 'package-dev'
25
     * @return bool
26
     */
27
    public static function checkLocalInstalledVersion(string $composerLockFile, string $packageName, string $floorVersion, string $packageMode = self::PACKAGE): bool
28
    {
29
        $localInstalledVersion = null;
1✔
30
        $composerLockFileContent = file_get_contents($composerLockFile);
1✔
31
        $arr = json_decode($composerLockFileContent, true);
1✔
32
        if (($arr !== false)) {
1✔
33
            if ($packageMode == self::PACKAGE_ALL) {
1✔
34
                $packageList = array_merge($arr['packages'] ?? [], $arr['packages-dev'] ?? []);
1✔
35
                $packageMap = array_column($packageList, NUll, 'name');
1✔
36
                if (isset($packageMap[$packageName])) {
1✔
37
                    $localInstalledVersion = $packageMap[$packageName]['version'];
1✔
38
                }
39
            } else if ($packageMode == self::PACKAGE_DEV) {
1✔
40
                if (isset($arr['packages-dev']) && is_array($arr['packages-dev'])) {
1✔
41
                    $packageMap = array_column($arr['packages-dev'], NUll, 'name');
1✔
42
                    if (isset($packageMap[$packageName])) {
1✔
43
                        $localInstalledVersion = $packageMap[$packageName]['version'];
1✔
44
                    }
45
                }
46
            } else if ($packageMode == self::PACKAGE) {
1✔
47
                if (isset($arr['packages']) && is_array($arr['packages'])) {
1✔
48
                    $packageMap = array_column($arr['packages'], NUll, 'name');
1✔
49
                    if (isset($packageMap[$packageName])) {
1✔
50
                        $localInstalledVersion = $packageMap[$packageName]['version'];
1✔
51
                    }
52
                }
53
            } else {
54
                return false;
×
55
            }
56
        }
57
        if ($localInstalledVersion) {
1✔
58
            $localInstalledVersion = ltrim($localInstalledVersion, 'v');// remove prefix 'v' if exists, "v1.2.3" => "1.2.3"
1✔
59
            return version_compare($localInstalledVersion, $floorVersion, '>=');
1✔
60
        }
61
        return false;
1✔
62
    }
63

64
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc