Skip to content

Commit a55842f

Browse files
authored
feat: drop support of php 8.1 and add tests for php 8.4 (#221)
1 parent 5c0baa5 commit a55842f

File tree

5 files changed

+119
-115
lines changed

5 files changed

+119
-115
lines changed

.circleci/config.yml

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ tests: &tests
2727
bin/doc
2828
PHP_CS_FIXER_IGNORE_ENV=1 composer run php-cs-fixer || (echo "Coding standards are not respected. Run 'composer run php-cs-fixer'" && exit 1)
2929
30-
tests_with_future_mode: &tests_with_future_mode
31-
run: |
32-
PHP_CS_FIXER_FUTURE_MODE=1 composer test -vvv
33-
bin/doc
34-
PHP_CS_FIXER_IGNORE_ENV=1 composer run php-cs-fixer || (echo "Coding standards are not respected. Run 'composer run php-cs-fixer'" && exit 1)
35-
3630
jobs:
3731
tests:
3832
parameters:
@@ -46,18 +40,6 @@ jobs:
4640
- <<: *composer_update
4741
- <<: *tests
4842

49-
tests-with-future-mode:
50-
parameters:
51-
php-version:
52-
type: string
53-
docker:
54-
- image: "php:<< parameters.php-version >>"
55-
steps:
56-
- checkout
57-
- <<: *install_composer
58-
- <<: *composer_update
59-
- <<: *tests_with_future_mode
60-
6143
tests-with-lowest-dependencies:
6244
parameters:
6345
php-version:
@@ -107,35 +89,27 @@ workflows:
10789
matrix:
10890
parameters:
10991
php-version:
110-
- "8.3"
92+
- "8.4"
11193
- tests:
11294
matrix:
11395
parameters:
11496
php-version:
115-
- "8.1"
116-
- "8.2"
117-
- "8.3"
118-
- tests-with-future-mode:
119-
matrix:
120-
parameters:
121-
php-version:
122-
- "8.1"
12397
- "8.2"
12498
- "8.3"
99+
- "8.4"
125100
- tests-with-lowest-dependencies:
126101
matrix:
127102
parameters:
128103
php-version:
129-
- "8.1"
130104
- "8.2"
131105
- "8.3"
106+
- "8.4"
132107
- release-test
133108
- release:
134109
requires:
135110
- release-test
136111
- documentation
137112
- tests
138-
- tests-with-future-mode
139113
- tests-with-lowest-dependencies
140114
filters:
141115
branches:

.php-cs-fixer.dist.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
->setRiskyAllowed(true)
1212
->setRules(
1313
RuleSetFactory::create()
14-
->per(2, true)
1514
->phpCsFixer(true)
16-
->php(8.1, true)
15+
->php(8.2, true)
1716
->pedrotroller(true)
1817
->enable('align_multiline_comment')
1918
->enable('array_indentation')
@@ -29,11 +28,10 @@
2928
->enable('no_superfluous_phpdoc_tags')
3029
->enable('ordered_imports')
3130
->enable('ordered_interfaces')
32-
->enable('simplified_null_return')
33-
->disable('simplified_null_return')
3431
->getRules()
3532
)
3633
->setUsingCache(false)
34+
->setUnsupportedPhpVersionAllowed(true)
3735
->registerCustomFixers(new Fixers())
3836
->setFinder(
3937
Finder::create()

bin/doc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@ $fixers = array_map(static function (AbstractFixer $fixer) {
2828
'deprecated' => $fixer->isDeprecated(),
2929
'replacement' => $fixer->getDeprecationReplacement(),
3030
'options' => array_map(
31-
static function (FixerOptionInterface $option) {
32-
return [
33-
'name' => $option->getName(),
34-
'description' => $option->getDescription(),
35-
'required' => false === $option->hasDefault(),
36-
'allowedValues' => $option->getAllowedValues(),
37-
'allowedTypes' => $option->getAllowedTypes(),
38-
'defaultValue' => $option->getDefault(),
39-
];
40-
},
31+
static fn (FixerOptionInterface $option) => [
32+
'name' => $option->getName(),
33+
'description' => $option->getDescription(),
34+
'required' => false === $option->hasDefault(),
35+
'allowedValues' => $option->getAllowedValues(),
36+
'allowedTypes' => $option->getAllowedTypes(),
37+
'defaultValue' => $option->getDefault(),
38+
],
4139
$fixer instanceof ConfigurableFixerInterface
4240
? $fixer->getConfigurationDefinition()->getOptions()
4341
: []

composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
"description": "PHP-CS-FIXER : my custom fixers",
44
"license": "MIT",
55
"require": {
6-
"php": "^8.1",
7-
"friendsofphp/php-cs-fixer": ">=3.59.3"
6+
"php": "^8.2",
7+
"friendsofphp/php-cs-fixer": "^3.87"
88
},
99
"require-dev": {
10-
"friendsofphp/php-cs-fixer": "^3.60",
11-
"phpspec/phpspec": "^7.0",
10+
"phpspec/phpspec": "^8.0",
1211
"sebastian/diff": "^4.0",
1312
"twig/twig": "^3.3",
1413
"webmozart/assert": "^1.10"

src/PedroTroller/CS/Fixer/RuleSetFactory.php

Lines changed: 103 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function create(array $rules = []): self
5555
);
5656
}
5757

58-
public function per(null|float|int $version = null, bool $risky = false): self
58+
public function per(float|int|null $version = null, bool $risky = false): self
5959
{
6060
$candidates = null !== $version
6161
? ['@PER-CS'.number_format($version, 1, '.', '')]
@@ -73,45 +73,55 @@ public function per(null|float|int $version = null, bool $risky = false): self
7373
continue;
7474
}
7575

76-
return self::create(array_merge(
77-
$this->rules,
78-
[$candidate => true],
79-
));
76+
return self::create(
77+
array_merge(
78+
$this->rules,
79+
[$candidate => true],
80+
)
81+
);
8082
}
8183

8284
throw new Exception('RuleSet not found: '.implode(', ', $candidates));
8385
}
8486

8587
public function psr0(): self
8688
{
87-
return self::create(array_merge(
88-
$this->rules,
89-
['@psr0' => true]
90-
));
89+
return self::create(
90+
array_merge(
91+
$this->rules,
92+
['@psr0' => true]
93+
)
94+
);
9195
}
9296

9397
public function psr1(): self
9498
{
95-
return self::create(array_merge(
96-
$this->rules,
97-
['@psr1' => true]
98-
));
99+
return self::create(
100+
array_merge(
101+
$this->rules,
102+
['@psr1' => true]
103+
)
104+
);
99105
}
100106

101107
public function psr2(): self
102108
{
103-
return self::create(array_merge(
104-
$this->rules,
105-
['@psr2' => true]
106-
));
109+
return self::create(
110+
array_merge(
111+
$this->rules,
112+
['@psr2' => true]
113+
)
114+
);
107115
}
108116

109117
public function psr4(): self
110118
{
111-
return self::create(array_merge(
112-
$this->rules,
113-
['@psr4' => true]
114-
));
119+
return self::create(
120+
array_merge(
121+
$this->rules,
122+
['@psr4' => true]
123+
)
124+
);
115125
}
116126

117127
public function symfony(bool $risky = false): self
@@ -122,10 +132,12 @@ public function symfony(bool $risky = false): self
122132
$rules['@Symfony:risky'] = true;
123133
}
124134

125-
return self::create(array_merge(
126-
$this->rules,
127-
$rules
128-
));
135+
return self::create(
136+
array_merge(
137+
$this->rules,
138+
$rules
139+
)
140+
);
129141
}
130142

131143
public function phpCsFixer(bool $risky = false): self
@@ -136,18 +148,22 @@ public function phpCsFixer(bool $risky = false): self
136148
$rules['@PhpCsFixer:risky'] = true;
137149
}
138150

139-
return self::create(array_merge(
140-
$this->rules,
141-
$rules
142-
));
151+
return self::create(
152+
array_merge(
153+
$this->rules,
154+
$rules
155+
)
156+
);
143157
}
144158

145159
public function doctrineAnnotation(): self
146160
{
147-
return self::create(array_merge(
148-
$this->rules,
149-
['@DoctrineAnnotation' => true]
150-
));
161+
return self::create(
162+
array_merge(
163+
$this->rules,
164+
['@DoctrineAnnotation' => true]
165+
)
166+
);
151167
}
152168

153169
public function php(float $version, bool $risky = false): self
@@ -165,10 +181,12 @@ public function php(float $version, bool $risky = false): self
165181
$config['array_syntax'] = ['syntax' => 'short'];
166182
}
167183

168-
return self::create(array_merge(
169-
$this->rules,
170-
$config
171-
));
184+
return self::create(
185+
array_merge(
186+
$this->rules,
187+
$config
188+
)
189+
);
172190
}
173191

174192
public function phpUnit(float $version, bool $risky = false): self
@@ -192,26 +210,32 @@ public function pedrotroller(bool $risky = false): self
192210
$rules[$fixer->getName()] = true;
193211
}
194212

195-
return self::create(array_merge(
196-
$this->rules,
197-
$rules
198-
));
213+
return self::create(
214+
array_merge(
215+
$this->rules,
216+
$rules
217+
)
218+
);
199219
}
200220

201221
public function enable(string $name, ?array $config = null): self
202222
{
203-
return self::create(array_merge(
204-
$this->rules,
205-
[$name => \is_array($config) ? $config : true]
206-
));
223+
return self::create(
224+
array_merge(
225+
$this->rules,
226+
[$name => \is_array($config) ? $config : true]
227+
)
228+
);
207229
}
208230

209231
public function disable(string $name): self
210232
{
211-
return self::create(array_merge(
212-
$this->rules,
213-
[$name => false]
214-
));
233+
return self::create(
234+
array_merge(
235+
$this->rules,
236+
[$name => false]
237+
)
238+
);
215239
}
216240

217241
private function migration(string $package, float $version, bool $risky): self
@@ -228,31 +252,42 @@ static function ($name) {
228252

229253
$rules = array_filter($rules);
230254

231-
$rules = array_filter($rules, static function ($versionAndRisky) use ($package) {
232-
[$rule, $rulePackage, $ruleVersion, $ruleRisky] = $versionAndRisky;
255+
$rules = array_filter(
256+
$rules,
257+
static function ($versionAndRisky) use ($package) {
258+
[$rule, $rulePackage, $ruleVersion, $ruleRisky] = $versionAndRisky;
233259

234-
return strtoupper($package) === strtoupper($rulePackage);
235-
});
260+
return strtoupper($package) === strtoupper($rulePackage);
261+
}
262+
);
236263

237-
$rules = array_filter($rules, static function ($versionAndRisky) use ($version) {
238-
[$rule, $rulePackage, $ruleVersion, $ruleRisky] = $versionAndRisky;
264+
$rules = array_filter(
265+
$rules,
266+
static function ($versionAndRisky) use ($version) {
267+
[$rule, $rulePackage, $ruleVersion, $ruleRisky] = $versionAndRisky;
239268

240-
return ((float) $ruleVersion / 10) <= $version;
241-
});
269+
return ((float) $ruleVersion / 10) <= $version;
270+
}
271+
);
242272

243-
$rules = array_filter($rules, static function ($versionAndRisky) use ($risky) {
244-
[$rule, $rulePackage, $ruleVersion, $ruleRisky] = $versionAndRisky;
273+
$rules = array_filter(
274+
$rules,
275+
static function ($versionAndRisky) use ($risky) {
276+
[$rule, $rulePackage, $ruleVersion, $ruleRisky] = $versionAndRisky;
245277

246-
if ($risky) {
247-
return true;
248-
}
278+
if ($risky) {
279+
return true;
280+
}
249281

250-
return empty($ruleRisky);
251-
});
282+
return empty($ruleRisky);
283+
}
284+
);
252285

253-
return self::create(array_merge(
254-
$this->rules,
255-
array_map(static fn () => true, $rules)
256-
));
286+
return self::create(
287+
array_merge(
288+
$this->rules,
289+
array_map(static fn () => true, $rules)
290+
)
291+
);
257292
}
258293
}

0 commit comments

Comments
 (0)