Skip to content

Commit 8053715

Browse files
committed
Update to PHP-CS-Fixer ^2.17
1 parent 278c4e8 commit 8053715

File tree

5 files changed

+25
-46
lines changed

5 files changed

+25
-46
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
"php": "^7.4 || 8.0",
1414
"ext-mbstring": "*",
1515
"ext-tokenizer": "*",
16-
"friendsofphp/php-cs-fixer": "^2.16"
16+
"friendsofphp/php-cs-fixer": "^2.17"
1717
},
1818
"require-dev": {
19-
"phpstan/phpstan": "^0.12.53",
19+
"phpstan/phpstan": "^0.12.59",
2020
"phpstan/phpstan-phpunit": "^0.12.16",
2121
"phpunit/phpunit": "^7.5.20",
2222
"slam/php-debug-r": "^1.6.1",
23-
"slam/phpstan-extensions": "^5.0.2",
23+
"slam/phpstan-extensions": "^5.1.0",
2424
"thecodingmachine/phpstan-strict-rules": "^0.12.1"
2525
},
2626
"autoload": {

lib/Config.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@
1010
final class Config extends PhpCsFixerConfig
1111
{
1212
public const RULES = [
13-
'@PhpCsFixer' => true,
14-
'@PhpCsFixer:risky' => true,
1513
'@DoctrineAnnotation' => true,
1614
'@PHP71Migration' => true,
1715
'@PHP71Migration:risky' => true,
1816
'@PHPUnit75Migration:risky' => true,
17+
'@PhpCsFixer' => true,
18+
'@PhpCsFixer:risky' => true,
1919
'Slam/final_abstract_public' => true,
2020
'Slam/final_internal_class' => true,
2121
'Slam/function_reference_space' => true,
2222
'Slam/php_only_braces' => true,
2323
'Slam/php_only_slam_inline_comment_spacer' => true,
2424
'Slam/utf8' => true,
2525
'align_multiline_comment' => ['comment_type' => 'all_multiline'],
26-
'backtick_to_shell_exec' => true,
2726
'binary_operator_spaces' => ['default' => 'align_single_space'],
2827
'braces' => false, // See Slam/php_only_braces
2928
'class_keyword_remove' => false,
@@ -36,20 +35,19 @@ final class Config extends PhpCsFixerConfig
3635
'final_class' => false,
3736
'final_internal_class' => false,
3837
'final_public_method_for_abstract_class' => false,
39-
'final_static_access' => true,
38+
// 'final_static_access' => true,
4039
'general_phpdoc_annotation_remove' => false,
4140
'global_namespace_import' => true,
41+
'group_import' => false,
4242
'header_comment' => false,
4343
'heredoc_indentation' => false,
44-
'linebreak_after_opening_tag' => true,
4544
'list_syntax' => true,
4645
'mb_str_functions' => false,
4746
'method_argument_space' => ['keep_multiple_spaces_after_comma' => true],
4847
'native_constant_invocation' => true,
4948
'native_function_invocation' => true,
5049
'no_blank_lines_before_namespace' => false,
5150
'no_multiline_whitespace_around_double_arrow' => false,
52-
'no_php4_constructor' => true,
5351
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
5452
'not_operator_with_space' => false,
5553
'not_operator_with_successor_space' => true,
@@ -62,18 +60,22 @@ final class Config extends PhpCsFixerConfig
6260
'php_unit_test_class_requires_covers' => false,
6361
'phpdoc_add_missing_param_annotation' => false,
6462
'phpdoc_line_span' => true,
63+
'phpdoc_tag_casing' => true,
6564
'phpdoc_to_param_type' => false,
6665
'phpdoc_to_return_type' => false,
6766
'pow_to_exponentiation' => false,
68-
'psr0' => true,
67+
// 'psr0' => true,
6968
'random_api_migration' => true,
69+
'regular_callable_call' => true,
7070
'self_static_accessor' => true,
7171
'simple_to_complex_string_variable' => false,
72+
'simplified_if_return' => true,
7273
'simplified_null_return' => false,
7374
'single_line_throw' => false,
7475
'space_after_semicolon' => true,
7576
'static_lambda' => false,
7677
'unary_operator_spaces' => false,
78+
'use_arrow_functions' => false,
7779
];
7880

7981
/**

phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ includes:
22
- phar://phpstan.phar/conf/config.level5.neon
33
- vendor/phpstan/phpstan-phpunit/extension.neon
44
- vendor/slam/phpstan-extensions/conf/slam-rules.neon
5-
- vendor/slam/phpstan-extensions/conf/thecodingmachine-rules.neon
65

76
parameters:
87
paths:

tests/AbstractFixerTestCase.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@ final protected function createFixer()
2222

2323
return new $fixerClass();
2424
}
25+
26+
protected function assertMatchesRegularExpression(string $format, string $string, string $message = ''): void
27+
{
28+
static::assertRegExp($format, $string, $message);
29+
}
2530
}

tests/ConfigTest.php

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
99
use PhpCsFixer\Fixer\FixerInterface;
1010
use PhpCsFixer\FixerFactory;
11-
use PhpCsFixer\RuleSet;
11+
use PhpCsFixer\RuleSet\RuleSet;
12+
use PhpCsFixer\RuleSet\RuleSets;
1213
use PHPUnit\Framework\TestCase;
13-
use ReflectionProperty;
1414
use SlamCsFixer\Config;
1515

1616
/**
@@ -43,7 +43,7 @@ public function testAllRulesAreSpecifiedAndDifferentFromRuleSets(): void
4343
// RuleSet strips all disabled rules
4444
foreach ($configRules as $name => $value) {
4545
if ('@' === $name[0]) {
46-
$defaultSetDefinitions[$name] = $this->resolveSubset($name);
46+
$defaultSetDefinitions[$name] = (new RuleSet(RuleSets::getSetDefinition($name)->getRules()))->getRules();
4747

4848
continue;
4949
}
@@ -85,7 +85,7 @@ public function testAllRulesAreSpecifiedAndDifferentFromRuleSets(): void
8585
$currentSets = \array_values(\array_filter(\array_keys($configRules), static function (string $fixerName): bool {
8686
return isset($fixerName[0]) && '@' === $fixerName[0];
8787
}));
88-
$defaultSets = $ruleSet->getSetDefinitionNames();
88+
$defaultSets = RuleSets::getSetDefinitionNames();
8989
$intersectSets = \array_values(\array_intersect($defaultSets, $currentSets));
9090
self::assertEquals($intersectSets, $currentSets, \sprintf('Rule sets must be ordered as the appear in %s', RuleSet::class));
9191

@@ -112,39 +112,12 @@ public function testFutureMode(): void
112112
public function testOverwrite(): void
113113
{
114114
$rules = (new Config())->getRules();
115-
self::assertTrue($rules['psr0']);
115+
$rule = 'global_namespace_import';
116+
self::assertTrue($rules[$rule]);
116117

117118
$newRules = (new Config([
118-
'psr0' => false,
119+
$rule => false,
119120
]))->getRules();
120-
self::assertFalse($newRules['psr0']);
121-
}
122-
123-
private function resolveSubset(string $setName): array
124-
{
125-
$rules = $this->getSetDefinition($setName);
126-
foreach ($rules as $name => $value) {
127-
if ('@' === $name[0]) {
128-
$set = $this->resolveSubset($name);
129-
unset($rules[$name]);
130-
$rules = \array_merge($rules, $set);
131-
} else {
132-
$rules[$name] = $value;
133-
}
134-
}
135-
136-
return $rules;
137-
}
138-
139-
private function getSetDefinition(string $name): array
140-
{
141-
if (null === $this->setDefinitions) {
142-
$refProp = (new ReflectionProperty(RuleSet::class, 'setDefinitions'));
143-
$refProp->setAccessible(true);
144-
$this->setDefinitions = $refProp->getValue(new RuleSet());
145-
$refProp->setAccessible(false);
146-
}
147-
148-
return $this->setDefinitions[$name];
121+
self::assertFalse($newRules[$rule]);
149122
}
150123
}

0 commit comments

Comments
 (0)