Skip to content

Commit 7114791

Browse files
committed
use new automatic rule sets for PHP versions
1 parent f09d7dd commit 7114791

File tree

3 files changed

+9
-64
lines changed

3 files changed

+9
-64
lines changed

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
"php": "^8.1"
77
},
88
"require-dev": {
9-
"friendsofphp/php-cs-fixer": "^3.87.1",
10-
"phpunit/phpunit": "^12.3.8",
11-
"phpstan/phpstan": "^2.1.22",
9+
"friendsofphp/php-cs-fixer": "^3.88.2",
10+
"phpunit/phpunit": "^12.4.1",
11+
"phpstan/phpstan": "^2.1.31",
1212
"phpstan/phpstan-deprecation-rules": "^2.0.3",
13-
"phpstan/phpstan-strict-rules": "^2.0.6",
14-
"rector/rector": "^2.1.4",
13+
"phpstan/phpstan-strict-rules": "^2.0.7",
14+
"rector/rector": "^2.2.3",
1515
"roave/security-advisories": "dev-latest",
1616
"phpstan/extension-installer": "^1.4.3"
1717
},

src/RuleSet.php

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class RuleSet
1212
public static function getValanticRules(): array
1313
{
1414
return [
15-
...self::addPhpVersionSpecificRules(),
15+
'@autoPHPMigration' => true,
16+
'@autoPHPMigration:risky' => true,
1617
'@PER-CS3.0' => true,
1718
'@PER-CS3.0:risky' => true,
1819
'@Symfony' => true,
@@ -126,42 +127,4 @@ public static function getValanticRules(): array
126127
],
127128
];
128129
}
129-
130-
private static function getCurrentPhpVersion(): string
131-
{
132-
return PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION;
133-
}
134-
135-
/**
136-
* @return array<string, bool|array<string, mixed>>
137-
*/
138-
private static function addPhpVersionSpecificRules(): array
139-
{
140-
$rules = [];
141-
$phpVersion = self::getCurrentPhpVersion();
142-
143-
$version = (int) str_replace('.', '', $phpVersion);
144-
145-
$availableRuleSets = \PhpCsFixer\RuleSet\RuleSets::getSetDefinitionNames();
146-
147-
for ($majorMinor = 80; $majorMinor <= 99; $majorMinor++) {
148-
if ($majorMinor > $version) {
149-
break;
150-
}
151-
152-
$migrationSet = sprintf('@PHP%dMigration', $majorMinor);
153-
154-
if (in_array($migrationSet, $availableRuleSets, true)) {
155-
$rules[$migrationSet] = true;
156-
}
157-
158-
$riskyMigrationSet = sprintf('%s:risky', $migrationSet);
159-
160-
if (in_array($riskyMigrationSet, $availableRuleSets, true)) {
161-
$rules[$riskyMigrationSet] = true;
162-
}
163-
}
164-
165-
return $rules;
166-
}
167130
}

tests/Unit/PhpCsFixerConfigTest.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Valantic\PhpCsFixerConfig\Tests\Unit;
66

77
use PhpCsFixer\Config;
8-
use PhpCsFixer\RuleSet\RuleSets;
98
use PHPUnit\Framework\TestCase;
109
use Valantic\PhpCsFixerConfig\ConfigFactory;
1110
use Valantic\PhpCsFixerConfig\RuleSet;
@@ -21,31 +20,14 @@ public function testGetValanticRules(): void
2120

2221
$this->assertNotEmpty($rules);
2322

23+
$this->assertArrayHasKey('@autoPHPMigration', $rules);
24+
$this->assertArrayHasKey('@autoPHPMigration:risky', $rules);
2425
$this->assertArrayHasKey('@PER-CS3.0', $rules);
2526
$this->assertArrayHasKey('@PER-CS3.0:risky', $rules);
2627
$this->assertArrayHasKey('@Symfony', $rules);
2728
$this->assertArrayHasKey('@Symfony:risky', $rules);
2829
$this->assertArrayHasKey('array_push', $rules);
2930
$this->assertArrayHasKey('yoda_style', $rules);
30-
31-
// Check that PHP version specific rules are included
32-
$phpVersion = PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION;
33-
$version = (int) str_replace('.', '', $phpVersion);
34-
35-
if ($version >= 80) {
36-
$this->assertArrayHasKey('@PHP80Migration', $rules);
37-
38-
// Check if the risky rule set exists
39-
$availableRuleSets = RuleSets::getSetDefinitionNames();
40-
41-
if (in_array('@PHP80Migration:risky', $availableRuleSets, true)) {
42-
$this->assertArrayHasKey('@PHP80Migration:risky', $rules);
43-
}
44-
}
45-
46-
if ($version >= 81) {
47-
$this->assertArrayHasKey('@PHP81Migration', $rules);
48-
}
4931
}
5032

5133
/**

0 commit comments

Comments
 (0)