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

keradus / PHP-CS-Fixer / 19958239208

05 Dec 2025 09:13AM UTC coverage: 93.181% (-1.0%) from 94.158%
19958239208

push

github

keradus
chore: .php-cs-fixer.dist.php - remove no longer needed rule, 'expectedDeprecation' annotation does not exist for long time

28928 of 31045 relevant lines covered (93.18%)

44.49 hits per line

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

8.33
/src/RuleSet/AutomaticMigrationSetTrait.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\RuleSet;
16

17
use Composer\Semver\Semver;
18
use PhpCsFixer\ComposerJsonReader;
19
use PhpCsFixer\ConfigurationException\UnresolvableAutoRuleSetConfigurationException;
20

21
/**
22
 * @internal
23
 *
24
 * @phpstan-require-implements AutomaticRuleSetDefinitionInterface
25
 *
26
 * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
27
 *
28
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
29
 */
30
trait AutomaticMigrationSetTrait
31
{
32
    private function calculateTargetSet(string $setName, string $entity, bool $isRisky): string
33
    {
34
        static $set = null;
6✔
35

36
        if (null === $set) {
6✔
37
            $actualVersion = self::calculateActualVersion($entity);
×
38

39
            $candidates = self::calculateCandidateSets($entity, $isRisky);
×
40
            $composerCandidates = Semver::rsort(array_keys($candidates));
×
41

42
            foreach ($composerCandidates as $candidate) {
×
43
                if (Semver::satisfies($actualVersion, '>='.$candidate)) {
×
44
                    $set = $candidates[$candidate]; // @phpstan-ignore offsetAccess.notFound
×
45

46
                    break;
×
47
                }
48
            }
49

50
            if (null === $set) {
×
51
                throw new UnresolvableAutoRuleSetConfigurationException(\sprintf('No migration set found feasible for %s (%s %s).', $setName, $entity, $actualVersion));
×
52
            }
53
        }
54

55
        return $set;
6✔
56
    }
57

58
    /**
59
     * @return list<AbstractMigrationSetDefinition>
60
     */
61
    private static function getMigrationSets(): array
62
    {
63
        static $sets = null;
×
64

65
        if (null === $sets) {
×
66
            $sets = array_values(array_filter(
×
67
                RuleSets::getSetDefinitions(),
×
68
                static fn (RuleSetDefinitionInterface $set): bool => !($set instanceof DeprecatedRuleSetDefinitionInterface) && is_subclass_of($set, AbstractMigrationSetDefinition::class),
×
69
            ));
×
70
        }
71

72
        return $sets;
×
73
    }
74

75
    private static function calculateActualVersion(string $entity): string
76
    {
77
        $composerJsonReader = ComposerJsonReader::createSingleton();
×
78

79
        if ('PHP' === $entity) {
×
80
            $version = $composerJsonReader->getPhp();
×
81
        } elseif ('PHPUnit' === $entity) {
×
82
            $version = $composerJsonReader->getPhpUnit();
×
83
        } else {
84
            throw new \InvalidArgumentException(\sprintf('Entity "%s" is not supported.', $entity));
×
85
        }
86

87
        if (null === $version) {
×
88
            throw new UnresolvableAutoRuleSetConfigurationException(\sprintf('Cannot detect %s version from "composer.json".', $entity));
×
89
        }
90

91
        return $version;
×
92
    }
93

94
    /**
95
     * @return array<string, string> [ 'major.minor' => '@SetName', ... ]
96
     */
97
    private static function calculateCandidateSets(string $entity, bool $isRisky): array
98
    {
99
        $candidates = [];
×
100
        foreach (self::getMigrationSets() as $set) {
×
101
            if ($set->getEntity() !== $entity) {
×
102
                continue;
×
103
            }
104

105
            if ($set->isRisky() !== $isRisky) {
×
106
                continue;
×
107
            }
108

109
            $candidates[$set->getVersionMajorMinor()] = $set->getName();
×
110
        }
111

112
        return $candidates;
×
113
    }
114
}
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