Skip to content

Commit

Permalink
Update to PHP-CS-Fixer ^2.17
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk committed Dec 11, 2020
1 parent 278c4e8 commit 8053715
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 46 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
"php": "^7.4 || 8.0",
"ext-mbstring": "*",
"ext-tokenizer": "*",
"friendsofphp/php-cs-fixer": "^2.16"
"friendsofphp/php-cs-fixer": "^2.17"
},
"require-dev": {
"phpstan/phpstan": "^0.12.53",
"phpstan/phpstan": "^0.12.59",
"phpstan/phpstan-phpunit": "^0.12.16",
"phpunit/phpunit": "^7.5.20",
"slam/php-debug-r": "^1.6.1",
"slam/phpstan-extensions": "^5.0.2",
"slam/phpstan-extensions": "^5.1.0",
"thecodingmachine/phpstan-strict-rules": "^0.12.1"
},
"autoload": {
Expand Down
16 changes: 9 additions & 7 deletions lib/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@
final class Config extends PhpCsFixerConfig
{
public const RULES = [
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'@DoctrineAnnotation' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'Slam/final_abstract_public' => true,
'Slam/final_internal_class' => true,
'Slam/function_reference_space' => true,
'Slam/php_only_braces' => true,
'Slam/php_only_slam_inline_comment_spacer' => true,
'Slam/utf8' => true,
'align_multiline_comment' => ['comment_type' => 'all_multiline'],
'backtick_to_shell_exec' => true,
'binary_operator_spaces' => ['default' => 'align_single_space'],
'braces' => false, // See Slam/php_only_braces
'class_keyword_remove' => false,
Expand All @@ -36,20 +35,19 @@ final class Config extends PhpCsFixerConfig
'final_class' => false,
'final_internal_class' => false,
'final_public_method_for_abstract_class' => false,
'final_static_access' => true,
// 'final_static_access' => true,
'general_phpdoc_annotation_remove' => false,
'global_namespace_import' => true,
'group_import' => false,
'header_comment' => false,
'heredoc_indentation' => false,
'linebreak_after_opening_tag' => true,
'list_syntax' => true,
'mb_str_functions' => false,
'method_argument_space' => ['keep_multiple_spaces_after_comma' => true],
'native_constant_invocation' => true,
'native_function_invocation' => true,
'no_blank_lines_before_namespace' => false,
'no_multiline_whitespace_around_double_arrow' => false,
'no_php4_constructor' => true,
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
'not_operator_with_space' => false,
'not_operator_with_successor_space' => true,
Expand All @@ -62,18 +60,22 @@ final class Config extends PhpCsFixerConfig
'php_unit_test_class_requires_covers' => false,
'phpdoc_add_missing_param_annotation' => false,
'phpdoc_line_span' => true,
'phpdoc_tag_casing' => true,
'phpdoc_to_param_type' => false,
'phpdoc_to_return_type' => false,
'pow_to_exponentiation' => false,
'psr0' => true,
// 'psr0' => true,
'random_api_migration' => true,
'regular_callable_call' => true,
'self_static_accessor' => true,
'simple_to_complex_string_variable' => false,
'simplified_if_return' => true,
'simplified_null_return' => false,
'single_line_throw' => false,
'space_after_semicolon' => true,
'static_lambda' => false,
'unary_operator_spaces' => false,
'use_arrow_functions' => false,
];

/**
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ includes:
- phar://phpstan.phar/conf/config.level5.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/slam/phpstan-extensions/conf/slam-rules.neon
- vendor/slam/phpstan-extensions/conf/thecodingmachine-rules.neon

parameters:
paths:
Expand Down
5 changes: 5 additions & 0 deletions tests/AbstractFixerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ final protected function createFixer()

return new $fixerClass();
}

protected function assertMatchesRegularExpression(string $format, string $string, string $message = ''): void
{
static::assertRegExp($format, $string, $message);
}
}
43 changes: 8 additions & 35 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
use PhpCsFixer\Fixer\FixerInterface;
use PhpCsFixer\FixerFactory;
use PhpCsFixer\RuleSet;
use PhpCsFixer\RuleSet\RuleSet;
use PhpCsFixer\RuleSet\RuleSets;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
use SlamCsFixer\Config;

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

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

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

$newRules = (new Config([
'psr0' => false,
$rule => false,
]))->getRules();
self::assertFalse($newRules['psr0']);
}

private function resolveSubset(string $setName): array
{
$rules = $this->getSetDefinition($setName);
foreach ($rules as $name => $value) {
if ('@' === $name[0]) {
$set = $this->resolveSubset($name);
unset($rules[$name]);
$rules = \array_merge($rules, $set);
} else {
$rules[$name] = $value;
}
}

return $rules;
}

private function getSetDefinition(string $name): array
{
if (null === $this->setDefinitions) {
$refProp = (new ReflectionProperty(RuleSet::class, 'setDefinitions'));
$refProp->setAccessible(true);
$this->setDefinitions = $refProp->getValue(new RuleSet());
$refProp->setAccessible(false);
}

return $this->setDefinitions[$name];
self::assertFalse($newRules[$rule]);
}
}

0 comments on commit 8053715

Please sign in to comment.