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

keradus / PHP-CS-Fixer / 17252691116

26 Aug 2025 11:09PM UTC coverage: 94.743% (-0.01%) from 94.755%
17252691116

push

github

keradus
chore: apply phpdoc_tag_no_named_arguments

28313 of 29884 relevant lines covered (94.74%)

45.64 hits per line

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

92.59
/src/Console/SelfUpdate/NewVersionChecker.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of PHP CS Fixer.
7
 *
8
 * (c) Fabien Potencier <fabien@symfony.com>
9
 *     Dariusz RumiƄski <dariusz.ruminski@gmail.com>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14

15
namespace PhpCsFixer\Console\SelfUpdate;
16

17
use Composer\Semver\Comparator;
18
use Composer\Semver\Semver;
19
use Composer\Semver\VersionParser;
20

21
/**
22
 * @internal
23
 *
24
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
25
 */
26
final class NewVersionChecker implements NewVersionCheckerInterface
27
{
28
    private GithubClientInterface $githubClient;
29

30
    private VersionParser $versionParser;
31

32
    /**
33
     * @var null|list<string>
34
     */
35
    private ?array $availableVersions = null;
36

37
    public function __construct(GithubClientInterface $githubClient)
38
    {
39
        $this->githubClient = $githubClient;
32✔
40
        $this->versionParser = new VersionParser();
32✔
41
    }
42

43
    public function getLatestVersion(): string
44
    {
45
        $this->retrieveAvailableVersions();
1✔
46

47
        return $this->availableVersions[0];
1✔
48
    }
49

50
    public function getLatestVersionOfMajor(int $majorVersion): ?string
51
    {
52
        $this->retrieveAvailableVersions();
3✔
53

54
        $semverConstraint = '^'.$majorVersion;
3✔
55

56
        foreach ($this->availableVersions as $availableVersion) {
3✔
57
            if (Semver::satisfies($availableVersion, $semverConstraint)) {
3✔
58
                return $availableVersion;
2✔
59
            }
60
        }
61

62
        return null;
1✔
63
    }
64

65
    public function compareVersions(string $versionA, string $versionB): int
66
    {
67
        $versionA = $this->versionParser->normalize($versionA);
28✔
68
        $versionB = $this->versionParser->normalize($versionB);
28✔
69

70
        if (Comparator::lessThan($versionA, $versionB)) {
28✔
71
            return -1;
24✔
72
        }
73

74
        if (Comparator::greaterThan($versionA, $versionB)) {
28✔
75
            return 1;
24✔
76
        }
77

78
        return 0;
4✔
79
    }
80

81
    private function retrieveAvailableVersions(): void
82
    {
83
        if (null !== $this->availableVersions) {
4✔
84
            return;
×
85
        }
86

87
        foreach ($this->githubClient->getTags() as $version) {
4✔
88
            try {
89
                $this->versionParser->normalize($version);
4✔
90

91
                if ('stable' === VersionParser::parseStability($version)) {
4✔
92
                    $this->availableVersions[] = $version;
4✔
93
                }
94
            } catch (\UnexpectedValueException $exception) {
×
95
                // not a valid version tag
96
            }
97
        }
98

99
        $versions = Semver::rsort($this->availableVersions);
4✔
100
        \assert(array_is_list($versions)); // Semver::rsort provides soft `array` type, let's validate and ensure proper type for SCA
4✔
101

102
        $this->availableVersions = $versions;
4✔
103
    }
104
}
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

© 2026 Coveralls, Inc