diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06b51c3..31c4aab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,6 +62,8 @@ jobs: run: tools/build.sh - name: Version run: test "$(bin/manticore-fmt version)" = "Manticore Fmt $(cat VERSION) (rules of PHP CS Fixer 3.95.27)" + - name: Format check (own code, .manticore-fmt.json) + run: bin/manticore-fmt check --diff - name: fmt-test (round trip, invariants, rule cases) run: tools/fmt-test.sh - name: Goldens (output-tree hashes per rule set and corpus) diff --git a/.gitignore b/.gitignore index 9a9b9b4..cca64cd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ bin/ dist/ bench/work/ .DS_Store +.manticore-fmt.cache diff --git a/.manticore-fmt.json b/.manticore-fmt.json new file mode 100644 index 0000000..2e4a024 --- /dev/null +++ b/.manticore-fmt.json @@ -0,0 +1,4 @@ +{ + "rules": {"@PER-CS3x0": true}, + "paths": ["src", "app", "tests/main.php"] +} diff --git a/src/Aliases.php b/src/Aliases.php index d4c52bb..74cebfc 100644 --- a/src/Aliases.php +++ b/src/Aliases.php @@ -122,10 +122,10 @@ public static function expand(string $name, mixed $value): ?array $ctl = Rules::enum($name, $o, 'position_after_control_structures', ['next', 'same'], 'same'); $fn = Rules::enum($name, $o, 'position_after_functions_and_oop_constructs', ['next', 'same'], 'next'); $anon = Rules::enum($name, $o, 'position_after_anonymous_constructs', ['next', 'same'], 'same'); - $pos = static fn (string $v): string => $v === 'next' ? 'next_line_unless_newline_at_signature_end' : 'same_line'; + $pos = static fn(string $v): string => $v === 'next' ? 'next_line_unless_newline_at_signature_end' : 'same_line'; return [ - ['single_space_around_construct', ['constructs_contain_a_single_space' => [], 'constructs_followed_by_a_single_space' => - ['elseif', 'for', 'foreach', 'if', 'match', 'while', 'use_lambda'], 'constructs_preceded_by_a_single_space' => ['use_lambda']]], + ['single_space_around_construct', ['constructs_contain_a_single_space' => [], 'constructs_followed_by_a_single_space' + => ['elseif', 'for', 'foreach', 'if', 'match', 'while', 'use_lambda'], 'constructs_preceded_by_a_single_space' => ['use_lambda']]], ['control_structure_braces', true], ['control_structure_continuation_position', ['position' => $ctl === 'next' ? 'next_line' : 'same_line']], ['declare_parentheses', true], diff --git a/src/Cli.php b/src/Cli.php index 642eaf2..4068cb3 100644 --- a/src/Cli.php +++ b/src/Cli.php @@ -268,7 +268,7 @@ private static function finish(Options $o, Config $cfg, array $results, int $tot } $bad = \array_merge($invalid, $failed); if ($bad !== []) { - \usort($bad, static fn (Outcome $a, Outcome $b): int => \strcmp($a->path, $b->path)); + \usort($bad, static fn(Outcome $a, Outcome $b): int => \strcmp($a->path, $b->path)); \fwrite(\STDERR, "\nFiles that were not fixed due to errors reported during " . ($invalid !== [] ? 'linting' : 'fixing') . ":\n"); $i = 0; foreach ($bad as $b) { diff --git a/src/Doc/Annotation.php b/src/Doc/Annotation.php index 8ba2abe..d125864 100644 --- a/src/Doc/Annotation.php +++ b/src/Doc/Annotation.php @@ -23,9 +23,7 @@ final class Annotation /** * @param Line[] $lines */ - public function __construct(public array $lines, public int $start, public int $end, public ?NsContext $ns = null) - { - } + public function __construct(public array $lines, public int $start, public int $end, public ?NsContext $ns = null) {} public function getTag(): Tag { @@ -65,8 +63,11 @@ public function getTypesContent(): ?string $this->simpleTypes = true; return $this->typesContent; } - if (Preg::match('{^(?:\h*\*|/\*\*)[\h*]*@' . $name . '\h+' . TypeExpression::REGEX_TYPES . '(?:(?:[*\h\v]|\&?[\.\$\s]).*)?\r?$}is', - $this->getContent(), $m)) { + if (Preg::match( + '{^(?:\h*\*|/\*\*)[\h*]*@' . $name . '\h+' . TypeExpression::REGEX_TYPES . '(?:(?:[*\h\v]|\&?[\.\$\s]).*)?\r?$}is', + $this->getContent(), + $m, + )) { $this->typesContent = (string) $m['types']; } } @@ -114,8 +115,8 @@ public function getNormalizedTypes(): array if ($t === null) { return []; } - $n = $t->mapTypes(static fn (TypeExpression $v): TypeExpression => new TypeExpression(\strtolower($v->toString()), null)) - ->sortTypes(static fn (TypeExpression $a, TypeExpression $b): int => $a->toString() <=> $b->toString()); + $n = $t->mapTypes(static fn(TypeExpression $v): TypeExpression => new TypeExpression(\strtolower($v->toString()), null)) + ->sortTypes(static fn(TypeExpression $a, TypeExpression $b): int => $a->toString() <=> $b->toString()); return $n->getTypes(); } diff --git a/src/Doc/DoctrineToken.php b/src/Doc/DoctrineToken.php index 3daee8b..9444e02 100644 --- a/src/Doc/DoctrineToken.php +++ b/src/Doc/DoctrineToken.php @@ -7,9 +7,7 @@ /** PhpCsFixer\Doctrine\Annotation\Token: a piece of a docblock as the Doctrine lexer sees it (T_NONE = plain text). */ final class DoctrineToken { - public function __construct(public int $type = DoctrineTokens::T_NONE, public string $content = '', public int $position = 0) - { - } + public function __construct(public int $type = DoctrineTokens::T_NONE, public string $content = '', public int $position = 0) {} public function isType(int $type): bool { diff --git a/src/Doc/Line.php b/src/Doc/Line.php index 4363bbc..a6b5df8 100644 --- a/src/Doc/Line.php +++ b/src/Doc/Line.php @@ -16,9 +16,7 @@ final class Line /** bit 0: useful computed, bit 1: useful, bit 2: tag computed, bit 3: tag */ private int $memo = 0; - public function __construct(private string $content, private bool $ascii = false) - { - } + public function __construct(private string $content, private bool $ascii = false) {} public function get(): string { diff --git a/src/Doc/NsContext.php b/src/Doc/NsContext.php index db9a8f1..693fcb2 100644 --- a/src/Doc/NsContext.php +++ b/src/Doc/NsContext.php @@ -15,6 +15,5 @@ public function __construct( public string $ns = '', public array $short = [], public array $full = [], - ) { - } + ) {} } diff --git a/src/Doc/Tag.php b/src/Doc/Tag.php index b827d88..63ab2c6 100644 --- a/src/Doc/Tag.php +++ b/src/Doc/Tag.php @@ -15,9 +15,7 @@ final class Tag private ?string $name = null; - public function __construct(public Line $line) - { - } + public function __construct(public Line $line) {} public function getName(): string { diff --git a/src/Doc/TypeExpression.php b/src/Doc/TypeExpression.php index d66d0ee..2846e17 100644 --- a/src/Doc/TypeExpression.php +++ b/src/Doc/TypeExpression.php @@ -15,7 +15,7 @@ final class TypeExpression public const REGEX_IDENTIFIER = '(?:(?!(?(?x) # one or several types separated by `|` or `&` -'.self::REGEX_TYPE.' +' . self::REGEX_TYPE . ' (?: \h*(?[|&])\h* (?&type) @@ -152,7 +152,7 @@ final class TypeExpression | (? # full name, e.g.: `int`, `\DateTime`, `\Foo\Bar`, `positive-int` \\\?+ - (?'.self::REGEX_IDENTIFIER.') + (?' . self::REGEX_IDENTIFIER . ') (?:[\\\\\-](?&identifier))*+ ) | @@ -314,7 +314,7 @@ public function removeDuplicateTypes(): TypeExpression $seen = []; $parts = []; foreach ($type->innerExpr as $e) { - $norm = $e->sortTypes(static fn (TypeExpression $a, TypeExpression $b): int => $a->value <=> $b->value)->value; + $norm = $e->sortTypes(static fn(TypeExpression $a, TypeExpression $b): int => $a->value <=> $b->value)->value; if (!\in_array($norm, $seen, true)) { $seen[] = $norm; $parts[] = $e->value; @@ -492,8 +492,10 @@ private function parse(): void $this->parseCommaSeparatedInnerTypes(\strlen(self::cap($m, 'generic_name')) + \strlen(self::cap($m, 'generic_start')), self::cap($m, 'generic_types')); } elseif (self::cap($m, 'callable') !== '' && self::capAt($m, 'callable') === 0) { $this->add(0, self::cap($m, 'callable_name')); - $this->parseCallableTemplateInnerTypes(\strlen(self::cap($m, 'callable_name')) + \strlen(self::cap($m, 'callable_template_start')), - self::cap($m, 'callable_template_inners')); + $this->parseCallableTemplateInnerTypes( + \strlen(self::cap($m, 'callable_name')) + \strlen(self::cap($m, 'callable_template_start')), + self::cap($m, 'callable_template_inners'), + ); $this->parseCallableArgumentTypes(\strlen(self::cap($m, 'callable_name')) + \strlen(self::cap($m, 'callable_template')) + \strlen(self::cap($m, 'callable_start')), self::cap($m, 'callable_arguments')); $ret = self::cap($m, 'callable_return'); diff --git a/src/DoctrineAnnotationRule.php b/src/DoctrineAnnotationRule.php index 605f0b0..0053379 100644 --- a/src/DoctrineAnnotationRule.php +++ b/src/DoctrineAnnotationRule.php @@ -17,9 +17,7 @@ abstract class DoctrineAnnotationRule extends DocRule private array $elements = []; /** @param string[] $ignoredTags */ - public function __construct(protected array $ignoredTags) - { - } + public function __construct(protected array $ignoredTags) {} /** the list upstream ignores by default */ public const IGNORED = ['abstract', 'access', 'code', 'deprec', 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc', 'magic', 'name', 'toc', 'tutorial', diff --git a/src/Edit.php b/src/Edit.php index db8cf8e..d71edc7 100644 --- a/src/Edit.php +++ b/src/Edit.php @@ -15,6 +15,5 @@ public function __construct( public int $split = -1, /** @var int[] more such offsets (a flat rule that left several) */ public array $splits = [], - ) { - } + ) {} } diff --git a/src/ExtraRules.php b/src/ExtraRules.php index c4a7ed9..f34cbe7 100644 --- a/src/ExtraRules.php +++ b/src/ExtraRules.php @@ -95,8 +95,10 @@ public static function make(string $name, string $lineEnding, array $opt = [], s } if ($name === 'numeric_literal_separator') { Rules::only($name, $opt, ['override_existing', 'strategy']); - return new NumericLiteralSeparator(Rules::bool($name, $opt, 'override_existing', false), - Rules::enum($name, $opt, 'strategy', ['use_separator', 'no_separator'], 'use_separator') === 'use_separator'); + return new NumericLiteralSeparator( + Rules::bool($name, $opt, 'override_existing', false), + Rules::enum($name, $opt, 'strategy', ['use_separator', 'no_separator'], 'use_separator') === 'use_separator', + ); } if ($name === 'heredoc_indentation') { Rules::only($name, $opt, ['indentation']); @@ -136,8 +138,11 @@ public static function make(string $name, string $lineEnding, array $opt = [], s } if ($name === 'ordered_interfaces') { Rules::only($name, $opt, ['order', 'direction', 'case_sensitive']); - return new OrderedInterfaces(Rules::enum($name, $opt, 'order', ['alpha', 'length'], 'alpha') === 'length', - Rules::enum($name, $opt, 'direction', ['ascend', 'descend'], 'ascend') === 'descend', Rules::bool($name, $opt, 'case_sensitive', false)); + return new OrderedInterfaces( + Rules::enum($name, $opt, 'order', ['alpha', 'length'], 'alpha') === 'length', + Rules::enum($name, $opt, 'direction', ['ascend', 'descend'], 'ascend') === 'descend', + Rules::bool($name, $opt, 'case_sensitive', false), + ); } if ($name === 'multiline_promoted_properties') { Rules::only($name, $opt, ['keep_blank_lines', 'minimum_number_of_parameters']); @@ -240,9 +245,14 @@ public static function make(string $name, string $lineEnding, array $opt = [], s throw new \InvalidArgumentException("$name: Provided RegEx is not valid."); } } - return new HeaderComment($header, $validator, Rules::enum($name, $opt, 'comment_type', ['PHPDoc', 'comment'], 'comment') === 'PHPDoc', + return new HeaderComment( + $header, + $validator, + Rules::enum($name, $opt, 'comment_type', ['PHPDoc', 'comment'], 'comment') === 'PHPDoc', Rules::enum($name, $opt, 'location', ['after_open', 'after_declare_strict'], 'after_declare_strict') === 'after_open', - Rules::enum($name, $opt, 'separate', ['both', 'top', 'bottom', 'none'], 'both'), $lineEnding); + Rules::enum($name, $opt, 'separate', ['both', 'top', 'bottom', 'none'], 'both'), + $lineEnding, + ); } return null; } diff --git a/src/FlatAttributeElement.php b/src/FlatAttributeElement.php index a9f9f18..f55060d 100644 --- a/src/FlatAttributeElement.php +++ b/src/FlatAttributeElement.php @@ -7,7 +7,5 @@ /** One attribute of a `#[A, B(1)]` group as AttributeAnalyzer::collectAttributes reports it: item range [start, end] (flat indexes) and the name as written. */ final class FlatAttributeElement { - public function __construct(public int $start, public int $end, public string $name) - { - } + public function __construct(public int $start, public int $end, public string $name) {} } diff --git a/src/FlatAttributeGroup.php b/src/FlatAttributeGroup.php index fe5fd8a..a291ba6 100644 --- a/src/FlatAttributeGroup.php +++ b/src/FlatAttributeGroup.php @@ -8,7 +8,5 @@ final class FlatAttributeGroup { /** @param FlatAttributeElement[] $attributes */ - public function __construct(public int $start, public int $end, public int $open, public int $close, public array $attributes) - { - } + public function __construct(public int $start, public int $end, public int $open, public int $close, public array $attributes) {} } diff --git a/src/FlatAttributes.php b/src/FlatAttributes.php index 9bdbb8e..a609fa4 100644 --- a/src/FlatAttributes.php +++ b/src/FlatAttributes.php @@ -172,4 +172,4 @@ private static function namespaceAt(FlatTokens $t, int $at): array } return ['', 0, $t->count()]; } -} \ No newline at end of file +} diff --git a/src/GapRule.php b/src/GapRule.php index 1f60921..5257ed0 100644 --- a/src/GapRule.php +++ b/src/GapRule.php @@ -77,9 +77,7 @@ public function isFileRule(): bool return false; } - public function fixFile(Source $s): void - { - } + public function fixFile(Source $s): void {} /** An EditRule: fixFile may record token edits (Source::edit), the Engine rebuilds the Source after it. */ public function isEditRule(): bool @@ -88,9 +86,7 @@ public function isEditRule(): bool } /** The path of the file the next prepare() / fixFile() run is about (a rule that depends on it, psr_autoloading, keeps it); '' = no file */ - public function forFile(string $path): void - { - } + public function forFile(string $path): void {} /** A rule that works on the raw file before it is lexed (encoding: a BOM); the Cli applies it in priority order. */ public function preParse(string $code): string diff --git a/src/Outcome.php b/src/Outcome.php index a933732..54126b1 100644 --- a/src/Outcome.php +++ b/src/Outcome.php @@ -28,9 +28,7 @@ final class Outcome /** peak resident bytes of the worker that formatted the file (0 when run in-process) */ public int $peak = 0; - public function __construct(public string $path, public int $status) - { - } + public function __construct(public string $path, public int $status) {} public function toWire(): string { diff --git a/src/PhpdocToTypeRule.php b/src/PhpdocToTypeRule.php index 7542ba1..9bb6028 100644 --- a/src/PhpdocToTypeRule.php +++ b/src/PhpdocToTypeRule.php @@ -47,15 +47,15 @@ public function __construct(bool $scalarTypes, bool $unionTypes, array $typesMap $this->reserved[$w] = true; } $tpl = \strtoupper($this->template()); - foreach (\explode(' ', $this->constant('FATAL_ALONE_'.$tpl)) as $w) { + foreach (\explode(' ', $this->constant('FATAL_ALONE_' . $tpl)) as $w) { if ($w !== '') { $this->fatal[$w] = true; } } - foreach (\explode(' ', $this->constant('ALONE_'.$tpl)) as $w) { + foreach (\explode(' ', $this->constant('ALONE_' . $tpl)) as $w) { $this->alone[$w] = true; } - foreach (\explode(' ', $this->constant('UNION_'.$tpl)) as $w) { + foreach (\explode(' ', $this->constant('UNION_' . $tpl)) as $w) { $this->union[$w] = true; } } @@ -67,7 +67,7 @@ abstract protected function isSkippedType(string $type): bool; private function constant(string $name): string { - return (string) \constant(TypeSyntax::class.'::'.$name); + return (string) \constant(TypeSyntax::class . '::' . $name); } /** the tag whose docblock a file needs to be changed at all */ diff --git a/src/Pool.php b/src/Pool.php index b581e50..8c9b8de 100644 --- a/src/Pool.php +++ b/src/Pool.php @@ -64,7 +64,7 @@ public static function run(array $files, int $workers, Processor $proc, ?Progres $size[$i] = (int) @\filesize($f); } $order = \array_keys($size); - \usort($order, static fn (int $a, int $b): int => $size[$b] <=> $size[$a] ?: $a <=> $b); + \usort($order, static fn(int $a, int $b): int => $size[$b] <=> $size[$a] ?: $a <=> $b); /** @var int[][] $share */ $share = []; /** @var int[] $load */ diff --git a/src/Processor.php b/src/Processor.php index 03c2428..3fed642 100644 --- a/src/Processor.php +++ b/src/Processor.php @@ -13,9 +13,7 @@ final class Processor * @param bool $diff fill Outcome::$diff * @param bool $applied fill Outcome::$applied (runs the rules one at a time) */ - public function __construct(private array $rules, private bool $dry, private bool $diff, private bool $applied, private ?Cache $cache = null) - { - } + public function __construct(private array $rules, private bool $dry, private bool $diff, private bool $applied, private ?Cache $cache = null) {} public function file(string $path): Outcome { diff --git a/src/Progress.php b/src/Progress.php index 1f7258d..df41d1f 100644 --- a/src/Progress.php +++ b/src/Progress.php @@ -14,9 +14,7 @@ final class Progress private int $errors = 0; private float $last = 0.0; - public function __construct(private int $total, private bool $color, private float $t0, private int $width = 0) - { - } + public function __construct(private int $total, private bool $color, private float $t0, private int $width = 0) {} public function start(): void { diff --git a/src/Reporter.php b/src/Reporter.php index fcc53e3..61a927b 100644 --- a/src/Reporter.php +++ b/src/Reporter.php @@ -45,8 +45,15 @@ private static function txt(array $changed, bool $dry, bool $withFixers, int $fi } $out .= "\n"; } - $sum = \sprintf("%s %d of %d %s in %.3f seconds, %.2f MB memory used", $dry ? 'Found' : 'Fixed', $i, $filesCount, - $dry ? 'files that can be fixed' : 'files', $seconds, $mb); + $sum = \sprintf( + "%s %d of %d %s in %.3f seconds, %.2f MB memory used", + $dry ? 'Found' : 'Fixed', + $i, + $filesCount, + $dry ? 'files that can be fixed' : 'files', + $seconds, + $mb, + ); return $out . "\n" . Ansi::paint($color, $i > 0 ? Ansi::YELLOW : Ansi::GREEN, $sum) . "\n"; } diff --git a/src/RiskyRules.php b/src/RiskyRules.php index 27b1b8d..415d326 100644 --- a/src/RiskyRules.php +++ b/src/RiskyRules.php @@ -117,8 +117,11 @@ public static function make(string $name, string $lineEnding, array $opt, string } if ($name === 'error_suppression') { Rules::only($name, $opt, ['mute_deprecation_error', 'noise_remaining_usages', 'noise_remaining_usages_exclude']); - return new ErrorSuppression(Rules::bool($name, $opt, 'mute_deprecation_error', true), Rules::bool($name, $opt, 'noise_remaining_usages', false), - isset($opt['noise_remaining_usages_exclude']) ? Rules::strList($name, $opt['noise_remaining_usages_exclude']) : []); + return new ErrorSuppression( + Rules::bool($name, $opt, 'mute_deprecation_error', true), + Rules::bool($name, $opt, 'noise_remaining_usages', false), + isset($opt['noise_remaining_usages_exclude']) ? Rules::strList($name, $opt['noise_remaining_usages_exclude']) : [], + ); } if ($name === 'function_to_constant') { Rules::only($name, $opt, ['functions']); @@ -249,8 +252,13 @@ public static function make(string $name, string $lineEnding, array $opt, string } } } - return new NativeConstantInvocation(Rules::bool($name, $opt, 'fix_built_in', true), $include, $exclude, Rules::enum($name, $opt, 'scope', ['all', 'namespaced'], 'all'), - Rules::bool($name, $opt, 'strict', true)); + return new NativeConstantInvocation( + Rules::bool($name, $opt, 'fix_built_in', true), + $include, + $exclude, + Rules::enum($name, $opt, 'scope', ['all', 'namespaced'], 'all'), + Rules::bool($name, $opt, 'strict', true), + ); } if ($name === 'no_unneeded_final_method') { Rules::only($name, $opt, ['private_methods']); @@ -359,8 +367,11 @@ public static function make(string $name, string $lineEnding, array $opt, string $methods[$m] = $v; } } - return new PhpUnitTestCaseStaticMethodCalls(Rules::enum($name, $opt, 'call_type', ['this', 'self', 'static'], 'static'), $methods, - Rules::enum($name, $opt, 'target', ['10.0', '11.0', 'newest'], '10.0')); + return new PhpUnitTestCaseStaticMethodCalls( + Rules::enum($name, $opt, 'call_type', ['this', 'self', 'static'], 'static'), + $methods, + Rules::enum($name, $opt, 'target', ['10.0', '11.0', 'newest'], '10.0'), + ); } if ($name === 'random_api_migration') { Rules::only($name, $opt, ['replacements']); diff --git a/src/Rule/AlignMultilineComment.php b/src/Rule/AlignMultilineComment.php index ff12a7d..1009942 100644 --- a/src/Rule/AlignMultilineComment.php +++ b/src/Rule/AlignMultilineComment.php @@ -16,9 +16,7 @@ final class AlignMultilineComment extends DocRule { /** @param string $type phpdocs_only | phpdocs_like | all_multiline */ - public function __construct(private string $type, private string $lineEnding) - { - } + public function __construct(private string $type, private string $lineEnding) {} public function name(): string { diff --git a/src/Rule/ArrayIndentation.php b/src/Rule/ArrayIndentation.php index 81bc1f7..7ccff99 100644 --- a/src/Rule/ArrayIndentation.php +++ b/src/Rule/ArrayIndentation.php @@ -31,9 +31,7 @@ final class ArrayIndentation extends GapRule private string $pli = ''; private string $pln = ''; - public function __construct(private string $indent = ' ') - { - } + public function __construct(private string $indent = ' ') {} public function name(): string { diff --git a/src/Rule/BlankLineAfterNamespace.php b/src/Rule/BlankLineAfterNamespace.php index a76877d..a1b7675 100644 --- a/src/Rule/BlankLineAfterNamespace.php +++ b/src/Rule/BlankLineAfterNamespace.php @@ -15,9 +15,7 @@ */ final class BlankLineAfterNamespace extends GapRule { - public function __construct(private string $le = "\n") - { - } + public function __construct(private string $le = "\n") {} public function name(): string { diff --git a/src/Rule/BlankLineAfterOpeningTag.php b/src/Rule/BlankLineAfterOpeningTag.php index 2759227..028ef4e 100644 --- a/src/Rule/BlankLineAfterOpeningTag.php +++ b/src/Rule/BlankLineAfterOpeningTag.php @@ -16,9 +16,7 @@ */ final class BlankLineAfterOpeningTag extends GapRule { - public function __construct(private string $le = "\n") - { - } + public function __construct(private string $le = "\n") {} public function name(): string { diff --git a/src/Rule/BlankLineBetweenImportGroups.php b/src/Rule/BlankLineBetweenImportGroups.php index 7295aa4..5dfc9fc 100644 --- a/src/Rule/BlankLineBetweenImportGroups.php +++ b/src/Rule/BlankLineBetweenImportGroups.php @@ -18,9 +18,7 @@ */ final class BlankLineBetweenImportGroups extends GapRule { - public function __construct(private string $le = "\n") - { - } + public function __construct(private string $le = "\n") {} public function name(): string { diff --git a/src/Rule/BlankLinesBeforeNamespace.php b/src/Rule/BlankLinesBeforeNamespace.php index 92e5f2f..3eb6393 100644 --- a/src/Rule/BlankLinesBeforeNamespace.php +++ b/src/Rule/BlankLinesBeforeNamespace.php @@ -15,9 +15,7 @@ */ final class BlankLinesBeforeNamespace extends GapRule { - public function __construct(private int $min = 2, private int $max = 2, private string $le = "\n") - { - } + public function __construct(private int $min = 2, private int $max = 2, private string $le = "\n") {} public function name(): string { diff --git a/src/Rule/BracesPosition.php b/src/Rule/BracesPosition.php index f6c2e81..5276b4f 100644 --- a/src/Rule/BracesPosition.php +++ b/src/Rule/BracesPosition.php @@ -36,8 +36,7 @@ public function __construct( private bool $anonClassesNext, private bool $allowEmptyAnonClasses, private bool $allowSingleLineAnonFunctions, - ) { - } + ) {} public function name(): string { diff --git a/src/Rule/CastSpaces.php b/src/Rule/CastSpaces.php index 8fe5d81..a087c72 100644 --- a/src/Rule/CastSpaces.php +++ b/src/Rule/CastSpaces.php @@ -16,9 +16,7 @@ final class CastSpaces extends GapRule { private const CASTS = [381, 382, 383, 384, 385, 386, 387, 388]; - public function __construct(private bool $single = true) - { - } + public function __construct(private bool $single = true) {} public function name(): string { diff --git a/src/Rule/ClassDefinition.php b/src/Rule/ClassDefinition.php index e7345ac..416ce78 100644 --- a/src/Rule/ClassDefinition.php +++ b/src/Rule/ClassDefinition.php @@ -38,8 +38,7 @@ public function __construct( private bool $inlineConstructorArguments = true, private string $le = "\n", private string $indent = ' ', - ) { - } + ) {} public function name(): string { diff --git a/src/Rule/ClassKeyword.php b/src/Rule/ClassKeyword.php index 1de39ef..da426d7 100644 --- a/src/Rule/ClassKeyword.php +++ b/src/Rule/ClassKeyword.php @@ -89,7 +89,7 @@ protected function run(Source $s, FlatTokens $t): void $slices = []; foreach ($subs as $q => $name) { $slices[$q] = [ - FlatTokens::code(\__McTokId::T_NAME_FULLY_QUALIFIED, '\\'.$name), + FlatTokens::code(\__McTokId::T_NAME_FULLY_QUALIFIED, '\\' . $name), FlatTokens::code(\__McTokId::T_DOUBLE_COLON, '::'), FlatTokens::code(\__McTokId::T_CLASS, 'class'), ]; diff --git a/src/Rule/ConcatSpace.php b/src/Rule/ConcatSpace.php index a5dc7c6..a203e7e 100644 --- a/src/Rule/ConcatSpace.php +++ b/src/Rule/ConcatSpace.php @@ -17,9 +17,7 @@ */ final class ConcatSpace extends GapRule { - public function __construct(private bool $one) - { - } + public function __construct(private bool $one) {} public function name(): string { diff --git a/src/Rule/ControlStructureBraces.php b/src/Rule/ControlStructureBraces.php index 5f44e43..b693edf 100644 --- a/src/Rule/ControlStructureBraces.php +++ b/src/Rule/ControlStructureBraces.php @@ -17,7 +17,6 @@ */ final class ControlStructureBraces extends EditRule { - private ?Source $s = null; /** @var array token index => text inserted right after it (before its gap), in insertion order */ private array $ins = []; @@ -223,7 +222,7 @@ private function statementEnd(int $pe): int return $q; } if ($k === \__McTokId::T_CLOSE_TAG) { - // getPrevNonWhitespace: the last comment of the gap before `?>`, else the token before it + // getPrevNonWhitespace: the last comment of the gap before the close tag, else the token before it $g = $s->gapBefore[$q]; if ($g !== '' && Gap::hasComment($g)) { return -$q - 2; diff --git a/src/Rule/EchoTagSyntax.php b/src/Rule/EchoTagSyntax.php index 9e18437..ba7c6c6 100644 --- a/src/Rule/EchoTagSyntax.php +++ b/src/Rule/EchoTagSyntax.php @@ -13,9 +13,7 @@ */ final class EchoTagSyntax extends EditRule { - public function __construct(private string $fn) - { - } + public function __construct(private string $fn) {} public function name(): string { diff --git a/src/Rule/EmptyLoopBody.php b/src/Rule/EmptyLoopBody.php index 5521fd5..32dd1e4 100644 --- a/src/Rule/EmptyLoopBody.php +++ b/src/Rule/EmptyLoopBody.php @@ -14,9 +14,7 @@ */ final class EmptyLoopBody extends EditRule { - public function __construct(private bool $braces) - { - } + public function __construct(private bool $braces) {} public function name(): string { diff --git a/src/Rule/FullyQualifiedStrictTypes.php b/src/Rule/FullyQualifiedStrictTypes.php index 5ceb874..ebddfac 100644 --- a/src/Rule/FullyQualifiedStrictTypes.php +++ b/src/Rule/FullyQualifiedStrictTypes.php @@ -60,9 +60,7 @@ final class FullyQualifiedStrictTypes extends EditRule private array $shortByNormalized = []; /** @param string[] $phpdocTags */ - public function __construct(private bool $leadingBackslash, private bool $importSymbols, private array $phpdocTags, private string $lineEnding) - { - } + public function __construct(private bool $leadingBackslash, private bool $importSymbols, private array $phpdocTags, private string $lineEnding) {} public function name(): string { @@ -1069,8 +1067,11 @@ private function fixPhpDoc(string $doc): string return $m[1] . $m[2] . $m[3] . $this->fixPhpDocType((string) $m[4]); }, $doc); if (\in_array('see', $tags, true) && \str_contains($new, '@see')) { - $new = Preg::replaceCallback('/([*{]\h*)@see(\h+)(' . self::REGEX_CLASS . ')(::(?:\$\w+|\w+\(\)))(?!(?!\})\S)/', - fn (array $m): string => $m[1] . '@see' . $m[2] . $this->fixPhpDocType((string) $m[3]) . $m[5], $new); + $new = Preg::replaceCallback( + '/([*{]\h*)@see(\h+)(' . self::REGEX_CLASS . ')(::(?:\$\w+|\w+\(\)))(?!(?!\})\S)/', + fn(array $m): string => $m[1] . '@see' . $m[2] . $this->fixPhpDocType((string) $m[3]) . $m[5], + $new, + ); } return $new; } diff --git a/src/Rule/FunctionDeclaration.php b/src/Rule/FunctionDeclaration.php index a2536f5..121f023 100644 --- a/src/Rule/FunctionDeclaration.php +++ b/src/Rule/FunctionDeclaration.php @@ -19,9 +19,7 @@ */ final class FunctionDeclaration extends GapRule { - public function __construct(private bool $closureFunctionOne = true, private bool $closureFnOne = true, private bool $trailingCommaSingleLine = false) - { - } + public function __construct(private bool $closureFunctionOne = true, private bool $closureFnOne = true, private bool $trailingCommaSingleLine = false) {} public function name(): string { diff --git a/src/Rule/GlobalNamespaceImport.php b/src/Rule/GlobalNamespaceImport.php index c96118f..264098f 100644 --- a/src/Rule/GlobalNamespaceImport.php +++ b/src/Rule/GlobalNamespaceImport.php @@ -23,9 +23,7 @@ */ final class GlobalNamespaceImport extends EditRule { - public function __construct(private ?bool $consts, private ?bool $functions, private ?bool $classes) - { - } + public function __construct(private ?bool $consts, private ?bool $functions, private ?bool $classes) {} public function name(): string { @@ -133,7 +131,7 @@ public function fixFile(Source $s): void $global = self::globals($uses, NsScan::USE_CLASS, false); if ($global !== []) { for ($t = $s->n; $t >= 0; $t--) { - DocRule::mapDocs($s, $t, static fn (string $d): string => self::qualifyDoc($d, $global)); + DocRule::mapDocs($s, $t, static fn(string $d): string => self::qualifyDoc($d, $global)); if ($t === $s->n) { continue; } diff --git a/src/Rule/HeredocClosingMarker.php b/src/Rule/HeredocClosingMarker.php index 9b43d68..259be05 100644 --- a/src/Rule/HeredocClosingMarker.php +++ b/src/Rule/HeredocClosingMarker.php @@ -15,9 +15,7 @@ final class HeredocClosingMarker extends GapRule { /** @param string[] $reserved */ - public function __construct(private string $marker, private array $reserved, private bool $explicit) - { - } + public function __construct(private string $marker, private array $reserved, private bool $explicit) {} public function name(): string { diff --git a/src/Rule/LineEnding.php b/src/Rule/LineEnding.php index 5c3317a..e1b690e 100644 --- a/src/Rule/LineEnding.php +++ b/src/Rule/LineEnding.php @@ -11,9 +11,7 @@ /** Parity target: PhpCsFixer\Fixer\Whitespace\LineEndingFixer (priority 0). */ final class LineEnding extends GapRule { - public function __construct(private string $lineEnding = "\n") - { - } + public function __construct(private string $lineEnding = "\n") {} public function name(): string { diff --git a/src/Rule/LinebreakAfterOpeningTag.php b/src/Rule/LinebreakAfterOpeningTag.php index e06cae7..a262e90 100644 --- a/src/Rule/LinebreakAfterOpeningTag.php +++ b/src/Rule/LinebreakAfterOpeningTag.php @@ -16,9 +16,7 @@ final class LinebreakAfterOpeningTag extends TextRule { private int $tag = -1; - public function __construct(private string $lineEnding) - { - } + public function __construct(private string $lineEnding) {} public function name(): string { diff --git a/src/Rule/LowercaseCast.php b/src/Rule/LowercaseCast.php index e19cc58..aa3d8da 100644 --- a/src/Rule/LowercaseCast.php +++ b/src/Rule/LowercaseCast.php @@ -13,9 +13,7 @@ */ final class LowercaseCast extends GapRule { - public function __construct(private bool $short = false) - { - } + public function __construct(private bool $short = false) {} public function name(): string { diff --git a/src/Rule/NoBlankLinesAfterClassOpening.php b/src/Rule/NoBlankLinesAfterClassOpening.php index f263119..20a2015 100644 --- a/src/Rule/NoBlankLinesAfterClassOpening.php +++ b/src/Rule/NoBlankLinesAfterClassOpening.php @@ -15,9 +15,7 @@ */ final class NoBlankLinesAfterClassOpening extends GapRule { - public function __construct(private string $le = "\n") - { - } + public function __construct(private string $le = "\n") {} public function name(): string { diff --git a/src/Rule/NoHomoglyphNames.php b/src/Rule/NoHomoglyphNames.php index 345902e..698d740 100644 --- a/src/Rule/NoHomoglyphNames.php +++ b/src/Rule/NoHomoglyphNames.php @@ -191,7 +191,7 @@ public function fixText(Source $s, int $i): ?string return null; } $count = 0; - $r = Preg::replaceCallback('/[^[:ascii:]]/', static fn (array $m): string => self::REPLACEMENTS[$m[0]] ?? $m[0], $t); + $r = Preg::replaceCallback('/[^[:ascii:]]/', static fn(array $m): string => self::REPLACEMENTS[$m[0]] ?? $m[0], $t); return $r === $t ? null : $r; } } diff --git a/src/Rule/NoLeadingNamespaceWhitespace.php b/src/Rule/NoLeadingNamespaceWhitespace.php index ea4816d..aa5b141 100644 --- a/src/Rule/NoLeadingNamespaceWhitespace.php +++ b/src/Rule/NoLeadingNamespaceWhitespace.php @@ -15,9 +15,7 @@ */ final class NoLeadingNamespaceWhitespace extends GapRule { - public function __construct(private string $lineEnding) - { - } + public function __construct(private string $lineEnding) {} public function name(): string { diff --git a/src/Rule/NoMixedEchoPrint.php b/src/Rule/NoMixedEchoPrint.php index ac301fe..b38e936 100644 --- a/src/Rule/NoMixedEchoPrint.php +++ b/src/Rule/NoMixedEchoPrint.php @@ -14,9 +14,7 @@ */ final class NoMixedEchoPrint extends GapRule { - public function __construct(private bool $toPrint) - { - } + public function __construct(private bool $toPrint) {} public function name(): string { diff --git a/src/Rule/NoMultipleStatementsPerLine.php b/src/Rule/NoMultipleStatementsPerLine.php index b46f251..077d3c4 100644 --- a/src/Rule/NoMultipleStatementsPerLine.php +++ b/src/Rule/NoMultipleStatementsPerLine.php @@ -18,9 +18,7 @@ */ final class NoMultipleStatementsPerLine extends GapRule { - public function __construct(private string $le = "\n") - { - } + public function __construct(private string $le = "\n") {} public function name(): string { diff --git a/src/Rule/NoSpacesAroundOffset.php b/src/Rule/NoSpacesAroundOffset.php index f397cdd..b55868f 100644 --- a/src/Rule/NoSpacesAroundOffset.php +++ b/src/Rule/NoSpacesAroundOffset.php @@ -15,9 +15,7 @@ */ final class NoSpacesAroundOffset extends GapRule { - public function __construct(private bool $inside, private bool $outside) - { - } + public function __construct(private bool $inside, private bool $outside) {} public function name(): string { diff --git a/src/Rule/NoSuperfluousPhpdocTags.php b/src/Rule/NoSuperfluousPhpdocTags.php index 10bd79f..462b137 100644 --- a/src/Rule/NoSuperfluousPhpdocTags.php +++ b/src/Rule/NoSuperfluousPhpdocTags.php @@ -31,9 +31,7 @@ final class NoSuperfluousPhpdocTags extends GapRule private ?string $ns = null; private ?string $symbol = null; - public function __construct(private bool $allowMixed, private bool $removeInheritdoc, private bool $allowHiddenParams, private bool $allowUnusedParams) - { - } + public function __construct(private bool $allowMixed, private bool $removeInheritdoc, private bool $allowHiddenParams, private bool $allowUnusedParams) {} public function name(): string { diff --git a/src/Rule/NoTrailingCommaInSingleline.php b/src/Rule/NoTrailingCommaInSingleline.php index ccf78db..61abc99 100644 --- a/src/Rule/NoTrailingCommaInSingleline.php +++ b/src/Rule/NoTrailingCommaInSingleline.php @@ -16,9 +16,7 @@ */ final class NoTrailingCommaInSingleline extends EditRule { - public function __construct(private bool $arguments, private bool $array, private bool $destructuring, private bool $groupImport) - { - } + public function __construct(private bool $arguments, private bool $array, private bool $destructuring, private bool $groupImport) {} public function name(): string { diff --git a/src/Rule/NoUnneededBraces.php b/src/Rule/NoUnneededBraces.php index adf5491..4b6cc51 100644 --- a/src/Rule/NoUnneededBraces.php +++ b/src/Rule/NoUnneededBraces.php @@ -20,9 +20,7 @@ final class NoUnneededBraces extends EditRule /** @var array */ private array $del = []; - public function __construct(private bool $namespaces) - { - } + public function __construct(private bool $namespaces) {} public function name(): string { diff --git a/src/Rule/NoWhitespaceBeforeCommaInArray.php b/src/Rule/NoWhitespaceBeforeCommaInArray.php index 4411b7d..6df7aab 100644 --- a/src/Rule/NoWhitespaceBeforeCommaInArray.php +++ b/src/Rule/NoWhitespaceBeforeCommaInArray.php @@ -19,9 +19,7 @@ final class NoWhitespaceBeforeCommaInArray extends GapRule /** @var int[][] */ private array $arrays = []; - public function __construct(private bool $afterHeredoc) - { - } + public function __construct(private bool $afterHeredoc) {} public function name(): string { diff --git a/src/Rule/NoWhitespaceInBlankLine.php b/src/Rule/NoWhitespaceInBlankLine.php index 0c4d583..0c2b9d7 100644 --- a/src/Rule/NoWhitespaceInBlankLine.php +++ b/src/Rule/NoWhitespaceInBlankLine.php @@ -11,9 +11,7 @@ /** Parity target: PhpCsFixer\Fixer\Whitespace\NoWhitespaceInBlankLineFixer (priority -99). */ final class NoWhitespaceInBlankLine extends GapRule { - public function __construct(private string $lineEnding = "\n") - { - } + public function __construct(private string $lineEnding = "\n") {} public function name(): string { diff --git a/src/Rule/NotOperatorWithSpace.php b/src/Rule/NotOperatorWithSpace.php index 7201617..151521f 100644 --- a/src/Rule/NotOperatorWithSpace.php +++ b/src/Rule/NotOperatorWithSpace.php @@ -15,9 +15,7 @@ */ final class NotOperatorWithSpace extends GapRule { - public function __construct(private bool $successorOnly = false) - { - } + public function __construct(private bool $successorOnly = false) {} public function name(): string { diff --git a/src/Rule/NumericLiteralSeparator.php b/src/Rule/NumericLiteralSeparator.php index 83ee9d2..eee2d94 100644 --- a/src/Rule/NumericLiteralSeparator.php +++ b/src/Rule/NumericLiteralSeparator.php @@ -13,9 +13,7 @@ */ final class NumericLiteralSeparator extends TextRule { - public function __construct(private bool $override, private bool $separate) - { - } + public function __construct(private bool $override, private bool $separate) {} public function name(): string { diff --git a/src/Rule/PhpUnitAttributes.php b/src/Rule/PhpUnitAttributes.php index 3435768..9da1e9e 100644 --- a/src/Rule/PhpUnitAttributes.php +++ b/src/Rule/PhpUnitAttributes.php @@ -205,8 +205,10 @@ private function items(FlatTokens $t, int $index, Annotation $annotation, string return $this->attribute($t, $index, 'CoversFunction', [self::str($parts[1])]); } if ($parts[1] !== '') { - return $this->attribute($t, $index, 'CoversMethod', \array_merge(self::classConstant($parts[0]), - [FlatTokens::code(44, ','), FlatTokens::ws(' '), self::str(\rtrim($parts[1], " ()\n\r\t\v\x00"))])); + return $this->attribute($t, $index, 'CoversMethod', \array_merge( + self::classConstant($parts[0]), + [FlatTokens::code(44, ','), FlatTokens::ws(' '), self::str(\rtrim($parts[1], " ()\n\r\t\v\x00"))], + )); } } return []; @@ -217,8 +219,10 @@ private function items(FlatTokens $t, int $index, Annotation $annotation, string } if (\str_contains($m[1], '::')) { [$class, $method] = \explode('::', $m[1]); - return $this->attribute($t, $index, 'DataProviderExternal', \array_merge(self::classConstant($class), - [FlatTokens::code(44, ','), FlatTokens::ws(' '), self::str(\rtrim($method, " ()\n\r\t\v\x00"))])); + return $this->attribute($t, $index, 'DataProviderExternal', \array_merge( + self::classConstant($class), + [FlatTokens::code(44, ','), FlatTokens::ws(' '), self::str(\rtrim($method, " ()\n\r\t\v\x00"))], + )); } return $this->attribute($t, $index, 'DataProvider', [self::str(\rtrim($m[1], " ()\n\r\t\v\x00"))]); } diff --git a/src/Rule/PhpUnitFqcnAnnotation.php b/src/Rule/PhpUnitFqcnAnnotation.php index 6ad35fb..c06bfd7 100644 --- a/src/Rule/PhpUnitFqcnAnnotation.php +++ b/src/Rule/PhpUnitFqcnAnnotation.php @@ -91,7 +91,7 @@ public function fixFile(Source $s): void } $start = $g >= 0 ? $g : $open + 1; for ($x = $start; $x <= $end; $x++) { - DocRule::mapDocs($s, $x, static fn (string $d): string => self::fixDoc($d), $x === $g ? $from : 0); + DocRule::mapDocs($s, $x, static fn(string $d): string => self::fixDoc($d), $x === $g ? $from : 0); } } } diff --git a/src/Rule/PhpUnitMethodCasing.php b/src/Rule/PhpUnitMethodCasing.php index 706befc..b47a0f1 100644 --- a/src/Rule/PhpUnitMethodCasing.php +++ b/src/Rule/PhpUnitMethodCasing.php @@ -168,7 +168,7 @@ private function updateDoc(FlatTokens $t, int $di): void continue; } $u = \preg_match('//u', $line) === 1 ? 'u' : ''; - $new = \preg_replace_callback('/(@depends\s+)(.+)(\b)/' . $u, fn (array $m): string => $m[1] . $this->casing($m[2]) . $m[3], $line); + $new = \preg_replace_callback('/(@depends\s+)(.+)(\b)/' . $u, fn(array $m): string => $m[1] . $this->casing($m[2]) . $m[3], $line); if ($new !== null && $new !== $line) { $lines[$k] = $new; $changed = true; diff --git a/src/Rule/PhpUnitNamespaced.php b/src/Rule/PhpUnitNamespaced.php index d5157f8..c26eed3 100644 --- a/src/Rule/PhpUnitNamespaced.php +++ b/src/Rule/PhpUnitNamespaced.php @@ -27,33 +27,33 @@ public function __construct(string $target) if ($target === 'newest' || $target === '6.0') { $this->regex = '/^PHPUnit_\w+$/i'; $classMap = [ - 'PHPUnit_Extensions_PhptTestCase' => 'PHPUnit\Runner\PhptTestCase', - 'PHPUnit_Framework_Constraint' => 'PHPUnit\Framework\Constraint\Constraint', - 'PHPUnit_Framework_Constraint_StringMatches' => 'PHPUnit\Framework\Constraint\StringMatchesFormatDescription', - 'PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider' => 'PHPUnit\Framework\Constraint\JsonMatchesErrorMessageProvider', - 'PHPUnit_Framework_Constraint_PCREMatch' => 'PHPUnit\Framework\Constraint\RegularExpression', - 'PHPUnit_Framework_Constraint_ExceptionMessageRegExp' => 'PHPUnit\Framework\Constraint\ExceptionMessageRegularExpression', - 'PHPUnit_Framework_Constraint_And' => 'PHPUnit\Framework\Constraint\LogicalAnd', - 'PHPUnit_Framework_Constraint_Or' => 'PHPUnit\Framework\Constraint\LogicalOr', - 'PHPUnit_Framework_Constraint_Not' => 'PHPUnit\Framework\Constraint\LogicalNot', - 'PHPUnit_Framework_Constraint_Xor' => 'PHPUnit\Framework\Constraint\LogicalXor', - 'PHPUnit_Framework_Error' => 'PHPUnit\Framework\Error\Error', - 'PHPUnit_Framework_TestSuite_DataProvider' => 'PHPUnit\Framework\DataProviderTestSuite', - 'PHPUnit_Framework_MockObject_Invocation_Static' => 'PHPUnit\Framework\MockObject\Invocation\StaticInvocation', - 'PHPUnit_Framework_MockObject_Invocation_Object' => 'PHPUnit\Framework\MockObject\Invocation\ObjectInvocation', - 'PHPUnit_Framework_MockObject_Stub_Return' => 'PHPUnit\Framework\MockObject\Stub\ReturnStub', - 'PHPUnit_Runner_Filter_Group_Exclude' => 'PHPUnit\Runner\Filter\ExcludeGroupFilterIterator', - 'PHPUnit_Runner_Filter_Group_Include' => 'PHPUnit\Runner\Filter\IncludeGroupFilterIterator', - 'PHPUnit_Runner_Filter_Test' => 'PHPUnit\Runner\Filter\NameFilterIterator', - 'PHPUnit_Util_PHP' => 'PHPUnit\Util\PHP\AbstractPhpProcess', - 'PHPUnit_Util_PHP_Default' => 'PHPUnit\Util\PHP\DefaultPhpProcess', - 'PHPUnit_Util_PHP_Windows' => 'PHPUnit\Util\PHP\WindowsPhpProcess', - 'PHPUnit_Util_Regex' => 'PHPUnit\Util\RegularExpression', - 'PHPUnit_Util_TestDox_ResultPrinter_XML' => 'PHPUnit\Util\TestDox\XmlResultPrinter', - 'PHPUnit_Util_TestDox_ResultPrinter_HTML' => 'PHPUnit\Util\TestDox\HtmlResultPrinter', - 'PHPUnit_Util_TestDox_ResultPrinter_Text' => 'PHPUnit\Util\TestDox\TextResultPrinter', - 'PHPUnit_Util_TestSuiteIterator' => 'PHPUnit\Framework\TestSuiteIterator', - 'PHPUnit_Util_XML' => 'PHPUnit\Util\Xml', + 'PHPUnit_Extensions_PhptTestCase' => 'PHPUnit\Runner\PhptTestCase', + 'PHPUnit_Framework_Constraint' => 'PHPUnit\Framework\Constraint\Constraint', + 'PHPUnit_Framework_Constraint_StringMatches' => 'PHPUnit\Framework\Constraint\StringMatchesFormatDescription', + 'PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider' => 'PHPUnit\Framework\Constraint\JsonMatchesErrorMessageProvider', + 'PHPUnit_Framework_Constraint_PCREMatch' => 'PHPUnit\Framework\Constraint\RegularExpression', + 'PHPUnit_Framework_Constraint_ExceptionMessageRegExp' => 'PHPUnit\Framework\Constraint\ExceptionMessageRegularExpression', + 'PHPUnit_Framework_Constraint_And' => 'PHPUnit\Framework\Constraint\LogicalAnd', + 'PHPUnit_Framework_Constraint_Or' => 'PHPUnit\Framework\Constraint\LogicalOr', + 'PHPUnit_Framework_Constraint_Not' => 'PHPUnit\Framework\Constraint\LogicalNot', + 'PHPUnit_Framework_Constraint_Xor' => 'PHPUnit\Framework\Constraint\LogicalXor', + 'PHPUnit_Framework_Error' => 'PHPUnit\Framework\Error\Error', + 'PHPUnit_Framework_TestSuite_DataProvider' => 'PHPUnit\Framework\DataProviderTestSuite', + 'PHPUnit_Framework_MockObject_Invocation_Static' => 'PHPUnit\Framework\MockObject\Invocation\StaticInvocation', + 'PHPUnit_Framework_MockObject_Invocation_Object' => 'PHPUnit\Framework\MockObject\Invocation\ObjectInvocation', + 'PHPUnit_Framework_MockObject_Stub_Return' => 'PHPUnit\Framework\MockObject\Stub\ReturnStub', + 'PHPUnit_Runner_Filter_Group_Exclude' => 'PHPUnit\Runner\Filter\ExcludeGroupFilterIterator', + 'PHPUnit_Runner_Filter_Group_Include' => 'PHPUnit\Runner\Filter\IncludeGroupFilterIterator', + 'PHPUnit_Runner_Filter_Test' => 'PHPUnit\Runner\Filter\NameFilterIterator', + 'PHPUnit_Util_PHP' => 'PHPUnit\Util\PHP\AbstractPhpProcess', + 'PHPUnit_Util_PHP_Default' => 'PHPUnit\Util\PHP\DefaultPhpProcess', + 'PHPUnit_Util_PHP_Windows' => 'PHPUnit\Util\PHP\WindowsPhpProcess', + 'PHPUnit_Util_Regex' => 'PHPUnit\Util\RegularExpression', + 'PHPUnit_Util_TestDox_ResultPrinter_XML' => 'PHPUnit\Util\TestDox\XmlResultPrinter', + 'PHPUnit_Util_TestDox_ResultPrinter_HTML' => 'PHPUnit\Util\TestDox\HtmlResultPrinter', + 'PHPUnit_Util_TestDox_ResultPrinter_Text' => 'PHPUnit\Util\TestDox\TextResultPrinter', + 'PHPUnit_Util_TestSuiteIterator' => 'PHPUnit\Framework\TestSuiteIterator', + 'PHPUnit_Util_XML' => 'PHPUnit\Util\Xml', ]; foreach ($classMap as $from => $to) { $this->map[\strtolower($from)] = $to; diff --git a/src/Rule/PhpUnitSizeClass.php b/src/Rule/PhpUnitSizeClass.php index 17212cf..5c7ac74 100644 --- a/src/Rule/PhpUnitSizeClass.php +++ b/src/Rule/PhpUnitSizeClass.php @@ -38,7 +38,13 @@ protected function applyClass(FlatTokens $t, int $start, int $end): void if ($prev >= 0 && self::is($t, $prev, \__McTokId::T_ABSTRACT)) { return; } - $this->ensureDocAnnotation($t, $classIndex, $this->group, ['small', 'medium', 'large'], - ['phpunit\framework\attributes\small', 'phpunit\framework\attributes\medium', 'phpunit\framework\attributes\large'], $this->lineEnding); + $this->ensureDocAnnotation( + $t, + $classIndex, + $this->group, + ['small', 'medium', 'large'], + ['phpunit\framework\attributes\small', 'phpunit\framework\attributes\medium', 'phpunit\framework\attributes\large'], + $this->lineEnding, + ); } } diff --git a/src/Rule/PhpdocAddMissingParamAnnotation.php b/src/Rule/PhpdocAddMissingParamAnnotation.php index 656cecc..200adff 100644 --- a/src/Rule/PhpdocAddMissingParamAnnotation.php +++ b/src/Rule/PhpdocAddMissingParamAnnotation.php @@ -22,9 +22,7 @@ final class PhpdocAddMissingParamAnnotation extends DocRule { private bool $consumed = false; - public function __construct(private bool $onlyUntyped, private string $lineEnding) - { - } + public function __construct(private bool $onlyUntyped, private string $lineEnding) {} public function name(): string { diff --git a/src/Rule/PhpdocAnnotationRemove.php b/src/Rule/PhpdocAnnotationRemove.php index 6dc4eb0..76f730a 100644 --- a/src/Rule/PhpdocAnnotationRemove.php +++ b/src/Rule/PhpdocAnnotationRemove.php @@ -15,9 +15,7 @@ final class PhpdocAnnotationRemove extends DocRule { /** @param string[] $annotations */ - public function __construct(private string $ruleName, private array $annotations, private bool $caseSensitive) - { - } + public function __construct(private string $ruleName, private array $annotations, private bool $caseSensitive) {} public function name(): string { diff --git a/src/Rule/PhpdocAnnotationWithoutDot.php b/src/Rule/PhpdocAnnotationWithoutDot.php index 08205bf..899ceb4 100644 --- a/src/Rule/PhpdocAnnotationWithoutDot.php +++ b/src/Rule/PhpdocAnnotationWithoutDot.php @@ -54,8 +54,12 @@ public function fixDoc(string $doc, Source $s, int $i, array $p, int $k): string $end->set(Preg::replace('/(?get())); $start = $d->lines[$a->start]; $opt = $a->supportTypes() ? '(?:' . \preg_quote(\implode('|', $a->getTypes()), '/') . '\s+(?:\$\w+\s+)?)' : ''; - $start->set(Preg::replaceCallback('/^(\s*\*\s*@\w+\s+' . $opt . ')(\p{Lu}?(?=\p{Ll}|\p{Zs}))(.*)$/', - static fn (array $m): string => $m[1] . \mb_strtolower((string) $m[2]) . $m[3], $start->get(), 1)); + $start->set(Preg::replaceCallback( + '/^(\s*\*\s*@\w+\s+' . $opt . ')(\p{Lu}?(?=\p{Ll}|\p{Zs}))(.*)$/', + static fn(array $m): string => $m[1] . \mb_strtolower((string) $m[2]) . $m[3], + $start->get(), + 1, + )); } return $d->getContent(); } diff --git a/src/Rule/PhpdocNoUselessInheritdoc.php b/src/Rule/PhpdocNoUselessInheritdoc.php index a41aeb2..1d4ee31 100644 --- a/src/Rule/PhpdocNoUselessInheritdoc.php +++ b/src/Rule/PhpdocNoUselessInheritdoc.php @@ -112,7 +112,7 @@ private function fixClassy(Source $s, int $t): int for ($q = \count($p) - 1; $q >= 0; $q--) { if ($p[$q] !== '' && !Gap::isSpace($p[$q])) { if (DocRule::isDocPiece($s, $t, $p[$q])) { - DocRule::mapDocs($s, $t, static fn (string $d): string => self::fixDoc($d), $q); + DocRule::mapDocs($s, $t, static fn(string $d): string => self::fixDoc($d), $q); } break; } @@ -129,7 +129,7 @@ private function fixClassy(Source $s, int $t): int $fix = !$ext; for ($x = $open + 1; $x <= $end; $x++) { if ($fix) { - DocRule::mapDocs($s, $x, static fn (string $d): string => self::fixDoc($d)); + DocRule::mapDocs($s, $x, static fn(string $d): string => self::fixDoc($d)); } if ($x < $end && $s->kind[$x] === \__McTokId::T_CLASS && $s->ct[$x] === 0) { $x = $this->fixClassy($s, $x); @@ -146,6 +146,6 @@ private static function fixDoc(string $d): string if (\stripos($d, 'inheritdoc') === false) { return $d; } - return Preg::replaceCallback('#(\h*(?:@{*|{*\h*@)\h*inheritdoc\h*)([^}]*)((?:}*)\h*)#i', static fn (array $m): string => ' ' . $m[2], $d); + return Preg::replaceCallback('#(\h*(?:@{*|{*\h*@)\h*inheritdoc\h*)([^}]*)((?:}*)\h*)#i', static fn(array $m): string => ' ' . $m[2], $d); } } diff --git a/src/Rule/PhpdocOrderByValue.php b/src/Rule/PhpdocOrderByValue.php index a5790a5..712d69d 100644 --- a/src/Rule/PhpdocOrderByValue.php +++ b/src/Rule/PhpdocOrderByValue.php @@ -17,9 +17,7 @@ final class PhpdocOrderByValue extends DocRule { /** @param string[] $annotations */ - public function __construct(private array $annotations) - { - } + public function __construct(private array $annotations) {} public function name(): string { @@ -80,7 +78,7 @@ public function fixDoc(string $doc, Source $s, int $i, array $p, int $k): string } /** @var int[] $order indexes of the keys in ksort(SORT_STRING) order */ $order = \array_keys($keys); - \usort($order, static fn (int $x, int $y): int => \strcmp($keys[$x], $keys[$y])); + \usort($order, static fn(int $x, int $y): int => \strcmp($keys[$x], $keys[$y])); if ($order === \array_keys($keys)) { continue; } diff --git a/src/Rule/PhpdocReturnSelfReference.php b/src/Rule/PhpdocReturnSelfReference.php index cb04707..528cd34 100644 --- a/src/Rule/PhpdocReturnSelfReference.php +++ b/src/Rule/PhpdocReturnSelfReference.php @@ -18,9 +18,7 @@ final class PhpdocReturnSelfReference extends GapRule { /** @param array $replacements lowercase from => to */ - public function __construct(private array $replacements) - { - } + public function __construct(private array $replacements) {} public function name(): string { @@ -100,7 +98,7 @@ public function fixFile(Source $s): void continue; } $rep = $this->replacements; - DocRule::mapDocs($s, $index, static fn (string $d): string => self::fixDoc($d, $rep), $q); + DocRule::mapDocs($s, $index, static fn(string $d): string => self::fixDoc($d, $rep), $q); } } diff --git a/src/Rule/PhpdocSeparation.php b/src/Rule/PhpdocSeparation.php index cc4a9eb..88dff07 100644 --- a/src/Rule/PhpdocSeparation.php +++ b/src/Rule/PhpdocSeparation.php @@ -17,9 +17,7 @@ final class PhpdocSeparation extends DocRule { /** @param string[][] $groups */ - public function __construct(private array $groups, private bool $skipUnlisted) - { - } + public function __construct(private array $groups, private bool $skipUnlisted) {} public function name(): string { diff --git a/src/Rule/PhpdocSummary.php b/src/Rule/PhpdocSummary.php index 452c9da..7bc845c 100644 --- a/src/Rule/PhpdocSummary.php +++ b/src/Rule/PhpdocSummary.php @@ -12,9 +12,7 @@ /** Parity target: PhpCsFixer\Fixer\Phpdoc\PhpdocSummaryFixer (priority 0): the summary ends with a full stop (or `!`, `?`, `:` ...). */ final class PhpdocSummary extends DocRule { - public function __construct(private string $lineEnding) - { - } + public function __construct(private string $lineEnding) {} public function name(): string { diff --git a/src/Rule/PhpdocTagNoNamedArguments.php b/src/Rule/PhpdocTagNoNamedArguments.php index e8ab67a..57b65c3 100644 --- a/src/Rule/PhpdocTagNoNamedArguments.php +++ b/src/Rule/PhpdocTagNoNamedArguments.php @@ -45,9 +45,7 @@ protected function candidate(Source $s): bool return false; } - protected function applyClass(FlatTokens $t, int $start, int $end): void - { - } + protected function applyClass(FlatTokens $t, int $start, int $end): void {} protected function run(Source $s, FlatTokens $t): void { diff --git a/src/Rule/PhpdocToComment.php b/src/Rule/PhpdocToComment.php index 9e5e2f5..f740b46 100644 --- a/src/Rule/PhpdocToComment.php +++ b/src/Rule/PhpdocToComment.php @@ -18,9 +18,7 @@ final class PhpdocToComment extends DocRule { /** @param string[] $ignoredTags lowercase */ - public function __construct(private array $ignoredTags, private bool $allowBeforeReturn) - { - } + public function __construct(private array $ignoredTags, private bool $allowBeforeReturn) {} public function name(): string { diff --git a/src/Rule/PhpdocTypesOrder.php b/src/Rule/PhpdocTypesOrder.php index 23a0650..25da4a6 100644 --- a/src/Rule/PhpdocTypesOrder.php +++ b/src/Rule/PhpdocTypesOrder.php @@ -15,9 +15,7 @@ final class PhpdocTypesOrder extends DocRule { /** @param string $nullAdjustment always_first | always_last | none */ - public function __construct(private bool $alpha, private string $nullAdjustment, private bool $caseSensitive) - { - } + public function __construct(private bool $alpha, private string $nullAdjustment, private bool $caseSensitive) {} public function name(): string { @@ -45,8 +43,11 @@ public function fixDoc(string $doc, Source $s, int $i, array $p, int $k): string $a->setTypes($this->sortTypes($t)); } $line = $d->lines[$a->start]; - $line->set(Preg::replaceCallback('/\*\h*@method\h+' . TypeExpression::REGEX_TYPES . '\h+\K(?&callable)/', - fn (array $m): string => \implode('|', $this->sortTypes(new TypeExpression((string) $m[0]))), $line->get())); + $line->set(Preg::replaceCallback( + '/\*\h*@method\h+' . TypeExpression::REGEX_TYPES . '\h+\K(?&callable)/', + fn(array $m): string => \implode('|', $this->sortTypes(new TypeExpression((string) $m[0]))), + $line->get(), + )); } return $d->getContent(); } diff --git a/src/Rule/ReturnTypeDeclaration.php b/src/Rule/ReturnTypeDeclaration.php index 145b63b..c2fc026 100644 --- a/src/Rule/ReturnTypeDeclaration.php +++ b/src/Rule/ReturnTypeDeclaration.php @@ -16,9 +16,7 @@ */ final class ReturnTypeDeclaration extends GapRule { - public function __construct(private bool $oneBefore = false) - { - } + public function __construct(private bool $oneBefore = false) {} public function name(): string { diff --git a/src/Rule/SingleBlankLineAtEof.php b/src/Rule/SingleBlankLineAtEof.php index 5bc92a6..0288037 100644 --- a/src/Rule/SingleBlankLineAtEof.php +++ b/src/Rule/SingleBlankLineAtEof.php @@ -16,9 +16,7 @@ */ final class SingleBlankLineAtEof extends GapRule { - public function __construct(private string $lineEnding = "\n") - { - } + public function __construct(private string $lineEnding = "\n") {} public function name(): string { diff --git a/src/Rule/SingleImportPerStatement.php b/src/Rule/SingleImportPerStatement.php index ee6ad8c..bb3deef 100644 --- a/src/Rule/SingleImportPerStatement.php +++ b/src/Rule/SingleImportPerStatement.php @@ -19,9 +19,7 @@ */ final class SingleImportPerStatement extends EditRule { - public function __construct(private string $le = "\n", private bool $group = true) - { - } + public function __construct(private string $le = "\n", private bool $group = true) {} public function name(): string { diff --git a/src/Rule/SingleLineAfterImports.php b/src/Rule/SingleLineAfterImports.php index d3b9068..b6e3b17 100644 --- a/src/Rule/SingleLineAfterImports.php +++ b/src/Rule/SingleLineAfterImports.php @@ -16,9 +16,7 @@ */ final class SingleLineAfterImports extends GapRule { - public function __construct(private string $le = "\n") - { - } + public function __construct(private string $le = "\n") {} public function name(): string { diff --git a/src/Rule/SingleLineCommentStyle.php b/src/Rule/SingleLineCommentStyle.php index 5c2652f..a6d1e27 100644 --- a/src/Rule/SingleLineCommentStyle.php +++ b/src/Rule/SingleLineCommentStyle.php @@ -16,9 +16,7 @@ */ final class SingleLineCommentStyle extends GapRule { - public function __construct(private bool $asterisk, private bool $hash) - { - } + public function __construct(private bool $asterisk, private bool $hash) {} public function name(): string { diff --git a/src/Rule/SingleQuote.php b/src/Rule/SingleQuote.php index fcfffee..cbee9c0 100644 --- a/src/Rule/SingleQuote.php +++ b/src/Rule/SingleQuote.php @@ -15,9 +15,7 @@ */ final class SingleQuote extends TextRule { - public function __construct(private bool $withSingleQuotes) - { - } + public function __construct(private bool $withSingleQuotes) {} public function name(): string { diff --git a/src/Rule/SpaceAfterSemicolon.php b/src/Rule/SpaceAfterSemicolon.php index 7bd1538..0ce4e28 100644 --- a/src/Rule/SpaceAfterSemicolon.php +++ b/src/Rule/SpaceAfterSemicolon.php @@ -15,9 +15,7 @@ */ final class SpaceAfterSemicolon extends GapRule { - public function __construct(private bool $removeInEmptyFor) - { - } + public function __construct(private bool $removeInEmptyFor) {} public function name(): string { diff --git a/src/Rule/StatementIndentation.php b/src/Rule/StatementIndentation.php index 7365332..d5cb996 100644 --- a/src/Rule/StatementIndentation.php +++ b/src/Rule/StatementIndentation.php @@ -38,9 +38,7 @@ final class StatementIndentation extends GapRule private array $pc = []; /** @param bool $compat upstream's `bracesFixerCompatibility` (the `braces` fixer runs statement_indentation this way) */ - public function __construct(private string $lineEnding, private bool $stick, private string $indent = " ", private bool $compat = false) - { - } + public function __construct(private string $lineEnding, private bool $stick, private string $indent = " ", private bool $compat = false) {} public function name(): string { diff --git a/src/Rule/StringImplicitBackslashes.php b/src/Rule/StringImplicitBackslashes.php index 731c04e..585fe02 100644 --- a/src/Rule/StringImplicitBackslashes.php +++ b/src/Rule/StringImplicitBackslashes.php @@ -14,9 +14,7 @@ */ final class StringImplicitBackslashes extends GapRule { - public function __construct(private string $single, private string $double, private string $heredoc) - { - } + public function __construct(private string $single, private string $double, private string $heredoc) {} public function name(): string { diff --git a/src/Rule/StringLineEnding.php b/src/Rule/StringLineEnding.php index 74bb36a..dfea165 100644 --- a/src/Rule/StringLineEnding.php +++ b/src/Rule/StringLineEnding.php @@ -14,9 +14,7 @@ */ final class StringLineEnding extends TextRule { - public function __construct(private string $lineEnding) - { - } + public function __construct(private string $lineEnding) {} public function name(): string { diff --git a/src/Rule/TrailingCommaInMultiline.php b/src/Rule/TrailingCommaInMultiline.php index 8611485..566f153 100644 --- a/src/Rule/TrailingCommaInMultiline.php +++ b/src/Rule/TrailingCommaInMultiline.php @@ -17,10 +17,14 @@ */ final class TrailingCommaInMultiline extends EditRule { - public function __construct(private bool $arrays = true, private bool $arguments = false, private bool $parameters = false, - private bool $match = false, private bool $destructuring = false, private bool $afterHeredoc = false) - { - } + public function __construct( + private bool $arrays = true, + private bool $arguments = false, + private bool $parameters = false, + private bool $match = false, + private bool $destructuring = false, + private bool $afterHeredoc = false, + ) {} public function name(): string { diff --git a/src/Rule/TypesSpaces.php b/src/Rule/TypesSpaces.php index b0d2ea7..034d609 100644 --- a/src/Rule/TypesSpaces.php +++ b/src/Rule/TypesSpaces.php @@ -16,9 +16,7 @@ */ final class TypesSpaces extends GapRule { - public function __construct(private bool $single = false) - { - } + public function __construct(private bool $single = false) {} public function name(): string { diff --git a/src/Rule/UnaryOperatorSpaces.php b/src/Rule/UnaryOperatorSpaces.php index 69d61c4..a194029 100644 --- a/src/Rule/UnaryOperatorSpaces.php +++ b/src/Rule/UnaryOperatorSpaces.php @@ -51,8 +51,18 @@ public function afterKinds(): array { $k = [\__McTokId::T_INC, \__McTokId::T_DEC]; if (!$this->onlyDecInc) { - \array_push($k, 33, 126, 64, \__McTokId::T_ELLIPSIS, 43, 45, 38, \__McTokId::T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG, - \__McTokId::T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG); + \array_push( + $k, + 33, + 126, + 64, + \__McTokId::T_ELLIPSIS, + 43, + 45, + 38, + \__McTokId::T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG, + \__McTokId::T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG, + ); } return $k; } diff --git a/src/Rule/WhitespaceAfterCommaInArray.php b/src/Rule/WhitespaceAfterCommaInArray.php index 6a408a3..0f0a138 100644 --- a/src/Rule/WhitespaceAfterCommaInArray.php +++ b/src/Rule/WhitespaceAfterCommaInArray.php @@ -19,9 +19,7 @@ final class WhitespaceAfterCommaInArray extends GapRule /** @var int[][] */ private array $arrays = []; - public function __construct(private bool $single) - { - } + public function __construct(private bool $single) {} public function name(): string { diff --git a/src/Rules.php b/src/Rules.php index cf41311..08bb76a 100644 --- a/src/Rules.php +++ b/src/Rules.php @@ -163,8 +163,16 @@ public static function make(string $name, string $lineEnding, array $opt = [], s throw new \InvalidArgumentException("$name: invalid value for {$keys[$k]}"); } } - return new BracesPosition($lineEnding, $next[0], $next[1], $next[2], $next[3], $next[4], - self::bool($name, $opt, $keys[5], true), self::bool($name, $opt, $keys[6], true)); + return new BracesPosition( + $lineEnding, + $next[0], + $next[1], + $next[2], + $next[3], + $next[4], + self::bool($name, $opt, $keys[5], true), + self::bool($name, $opt, $keys[6], true), + ); } if ($name === 'binary_operator_spaces') { self::only($name, $opt, ['default', 'operators']); @@ -207,8 +215,14 @@ public static function make(string $name, string $lineEnding, array $opt = [], s self::only($name, $opt, ['keep_multiple_spaces_after_comma', 'on_multiline', 'after_heredoc', 'attribute_placement']); $om = self::enum($name, $opt, 'on_multiline', ['ignore', 'ensure_fully_multiline'], 'ensure_fully_multiline'); $ap = self::enum($name, $opt, 'attribute_placement', ['ignore', 'standalone'], 'standalone'); - return new MethodArgumentSpace($lineEnding, self::bool($name, $opt, 'keep_multiple_spaces_after_comma', false), $om === 'ensure_fully_multiline', - self::bool($name, $opt, 'after_heredoc', false), $ap === 'standalone', $indent); + return new MethodArgumentSpace( + $lineEnding, + self::bool($name, $opt, 'keep_multiple_spaces_after_comma', false), + $om === 'ensure_fully_multiline', + self::bool($name, $opt, 'after_heredoc', false), + $ap === 'standalone', + $indent, + ); } if ($name === 'unary_operator_spaces') { self::only($name, $opt, ['only_dec_inc']); @@ -311,14 +325,23 @@ public static function make(string $name, string $lineEnding, array $opt = [], s } if ($name === 'function_declaration') { self::only($name, $opt, ['closure_function_spacing', 'closure_fn_spacing', 'trailing_comma_single_line']); - return new FunctionDeclaration(self::enum($name, $opt, 'closure_function_spacing', ['one', 'none'], 'one') === 'one', - self::enum($name, $opt, 'closure_fn_spacing', ['one', 'none'], 'one') === 'one', self::bool($name, $opt, 'trailing_comma_single_line', false)); + return new FunctionDeclaration( + self::enum($name, $opt, 'closure_function_spacing', ['one', 'none'], 'one') === 'one', + self::enum($name, $opt, 'closure_fn_spacing', ['one', 'none'], 'one') === 'one', + self::bool($name, $opt, 'trailing_comma_single_line', false), + ); } if ($name === 'class_definition') { self::only($name, $opt, ['multi_line_extends_each_single_line', 'single_item_single_line', 'single_line', 'space_before_parenthesis', 'inline_constructor_arguments']); - return new ClassDefinition(self::bool($name, $opt, 'single_line', false), self::bool($name, $opt, 'single_item_single_line', false), - self::bool($name, $opt, 'multi_line_extends_each_single_line', false), self::bool($name, $opt, 'space_before_parenthesis', false), - self::bool($name, $opt, 'inline_constructor_arguments', true), $lineEnding, $indent); + return new ClassDefinition( + self::bool($name, $opt, 'single_line', false), + self::bool($name, $opt, 'single_item_single_line', false), + self::bool($name, $opt, 'multi_line_extends_each_single_line', false), + self::bool($name, $opt, 'space_before_parenthesis', false), + self::bool($name, $opt, 'inline_constructor_arguments', true), + $lineEnding, + $indent, + ); } if ($name === 'single_line_after_imports') { return new SingleLineAfterImports($lineEnding); @@ -391,8 +414,14 @@ public static function make(string $name, string $lineEnding, array $opt = [], s if ($name === 'trailing_comma_in_multiline') { self::only($name, $opt, ['after_heredoc', 'elements']); $el = self::subset($name, $opt, 'elements', ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters'], ['arrays']); - return new TrailingCommaInMultiline(\in_array('arrays', $el, true), \in_array('arguments', $el, true), \in_array('parameters', $el, true), - \in_array('match', $el, true), \in_array('array_destructuring', $el, true), self::bool($name, $opt, 'after_heredoc', false)); + return new TrailingCommaInMultiline( + \in_array('arrays', $el, true), + \in_array('arguments', $el, true), + \in_array('parameters', $el, true), + \in_array('match', $el, true), + \in_array('array_destructuring', $el, true), + self::bool($name, $opt, 'after_heredoc', false), + ); } if ($name === 'nullable_type_declaration') { self::only($name, $opt, ['syntax']); @@ -403,8 +432,11 @@ public static function make(string $name, string $lineEnding, array $opt = [], s } if ($name === 'ordered_types') { self::only($name, $opt, ['sort_algorithm', 'null_adjustment', 'case_sensitive']); - return new OrderedTypes(self::enum($name, $opt, 'sort_algorithm', ['alpha', 'none'], 'alpha') === 'alpha', - self::enum($name, $opt, 'null_adjustment', ['always_first', 'always_last', 'none'], 'always_first'), self::bool($name, $opt, 'case_sensitive', false)); + return new OrderedTypes( + self::enum($name, $opt, 'sort_algorithm', ['alpha', 'none'], 'alpha') === 'alpha', + self::enum($name, $opt, 'null_adjustment', ['always_first', 'always_last', 'none'], 'always_first'), + self::bool($name, $opt, 'case_sensitive', false), + ); } if ($name === 'ordered_imports') { self::only($name, $opt, ['sort_algorithm', 'imports_order', 'case_sensitive']); @@ -440,8 +472,12 @@ public static function make(string $name, string $lineEnding, array $opt = [], s } if ($name === 'statement_indentation') { self::only($name, $opt, ['stick_comment_to_next_continuous_control_statement', 'braces_fixer_compatibility']); - return new StatementIndentation($lineEnding, self::bool($name, $opt, 'stick_comment_to_next_continuous_control_statement', false), $indent, - self::bool($name, $opt, 'braces_fixer_compatibility', false)); + return new StatementIndentation( + $lineEnding, + self::bool($name, $opt, 'stick_comment_to_next_continuous_control_statement', false), + $indent, + self::bool($name, $opt, 'braces_fixer_compatibility', false), + ); } return SymRules::make($name, $lineEnding, $opt, $indent); } @@ -460,14 +496,22 @@ private static function makeDoc(string $name, string $lineEnding, array $opt, st } if ($name === 'general_phpdoc_annotation_remove') { self::only($name, $opt, ['annotations', 'case_sensitive']); - return new PhpdocAnnotationRemove($name, isset($opt['annotations']) ? self::strList($name, $opt['annotations']) : [], - self::bool($name, $opt, 'case_sensitive', true)); + return new PhpdocAnnotationRemove( + $name, + isset($opt['annotations']) ? self::strList($name, $opt['annotations']) : [], + self::bool($name, $opt, 'case_sensitive', true), + ); } if ($name === 'general_phpdoc_tag_rename') { self::only($name, $opt, ['fix_annotation', 'fix_inline', 'replacements', 'case_sensitive']); $cs = self::bool($name, $opt, 'case_sensitive', false); - return new PhpdocTagRename($name, self::tagReplacements($name, $opt['replacements'] ?? [], $cs), $cs, - self::bool($name, $opt, 'fix_annotation', true), self::bool($name, $opt, 'fix_inline', true)); + return new PhpdocTagRename( + $name, + self::tagReplacements($name, $opt['replacements'] ?? [], $cs), + $cs, + self::bool($name, $opt, 'fix_annotation', true), + self::bool($name, $opt, 'fix_inline', true), + ); } if ($name === 'phpdoc_no_alias_tag') { self::only($name, $opt, ['replacements']); @@ -534,8 +578,13 @@ private static function makeDoc(string $name, string $lineEnding, array $opt, st } if ($name === 'phpdoc_scalar') { self::only($name, $opt, ['types']); - return new PhpdocScalar(self::subset($name, $opt, 'types', \array_keys(PhpdocScalar::TYPES_MAP), - ['boolean', 'callback', 'double', 'integer', 'real', 'str'])); + return new PhpdocScalar(self::subset( + $name, + $opt, + 'types', + \array_keys(PhpdocScalar::TYPES_MAP), + ['boolean', 'callback', 'double', 'integer', 'real', 'str'], + )); } if ($name === 'phpdoc_types') { self::only($name, $opt, ['groups', 'exclude']); @@ -576,16 +625,25 @@ private static function makeDoc(string $name, string $lineEnding, array $opt, st } elseif (!\is_int($sp) || $sp <= 0) { throw new \InvalidArgumentException("$name: all spacings must be greater than zero"); } - return new PhpdocAlign(isset($opt['tags']) ? self::strList($name, $opt['tags']) : ['method', 'param', 'property', 'return', 'throws', 'type', 'var'], - self::enum($name, $opt, 'align', ['left', 'vertical'], 'vertical') === 'vertical', $sp, $map, $lineEnding); + return new PhpdocAlign( + isset($opt['tags']) ? self::strList($name, $opt['tags']) : ['method', 'param', 'property', 'return', 'throws', 'type', 'var'], + self::enum($name, $opt, 'align', ['left', 'vertical'], 'vertical') === 'vertical', + $sp, + $map, + $lineEnding, + ); } if ($name === 'fully_qualified_strict_types') { self::only($name, $opt, ['leading_backslash_in_global_namespace', 'import_symbols', 'phpdoc_tags']); $tags = isset($opt['phpdoc_tags']) ? self::strList($name, $opt['phpdoc_tags']) : ['param', 'phpstan-param', 'phpstan-property', 'phpstan-property-read', 'phpstan-property-write', 'phpstan-return', 'phpstan-var', 'property', 'property-read', 'property-write', 'psalm-param', 'psalm-property', 'psalm-property-read', 'psalm-property-write', 'psalm-return', 'psalm-var', 'return', 'see', 'throws', 'var']; - return new FullyQualifiedStrictTypes(self::bool($name, $opt, 'leading_backslash_in_global_namespace', false), - self::bool($name, $opt, 'import_symbols', false), $tags, $lineEnding); + return new FullyQualifiedStrictTypes( + self::bool($name, $opt, 'leading_backslash_in_global_namespace', false), + self::bool($name, $opt, 'import_symbols', false), + $tags, + $lineEnding, + ); } if ($name === 'global_namespace_import') { self::only($name, $opt, ['import_constants', 'import_functions', 'import_classes']); @@ -601,8 +659,12 @@ private static function makeDoc(string $name, string $lineEnding, array $opt, st } if ($name === 'no_superfluous_phpdoc_tags') { self::only($name, $opt, ['allow_mixed', 'remove_inheritdoc', 'allow_hidden_params', 'allow_unused_params']); - return new NoSuperfluousPhpdocTags(self::bool($name, $opt, 'allow_mixed', false), self::bool($name, $opt, 'remove_inheritdoc', false), - self::bool($name, $opt, 'allow_hidden_params', false), self::bool($name, $opt, 'allow_unused_params', false)); + return new NoSuperfluousPhpdocTags( + self::bool($name, $opt, 'allow_mixed', false), + self::bool($name, $opt, 'remove_inheritdoc', false), + self::bool($name, $opt, 'allow_hidden_params', false), + self::bool($name, $opt, 'allow_unused_params', false), + ); } if ($name === 'phpdoc_to_comment') { self::only($name, $opt, ['ignored_tags', 'allow_before_return_statement']); @@ -670,8 +732,11 @@ private static function makeDoc(string $name, string $lineEnding, array $opt, st } if ($name === 'phpdoc_types_order') { self::only($name, $opt, ['sort_algorithm', 'null_adjustment', 'case_sensitive']); - return new PhpdocTypesOrder(self::enum($name, $opt, 'sort_algorithm', ['alpha', 'none'], 'alpha') === 'alpha', - self::enum($name, $opt, 'null_adjustment', ['always_first', 'always_last', 'none'], 'always_first'), self::bool($name, $opt, 'case_sensitive', false)); + return new PhpdocTypesOrder( + self::enum($name, $opt, 'sort_algorithm', ['alpha', 'none'], 'alpha') === 'alpha', + self::enum($name, $opt, 'null_adjustment', ['always_first', 'always_last', 'none'], 'always_first'), + self::bool($name, $opt, 'case_sensitive', false), + ); } return null; } diff --git a/src/Source.php b/src/Source.php index c9c5eaa..3478cfd 100644 --- a/src/Source.php +++ b/src/Source.php @@ -405,7 +405,7 @@ public function render(): string $this->over[$t] = 'namespace'; // an edit changes the file: upstream's transformer literal shows (see join) } $ed = $this->edits; - \usort($ed, static fn (Edit $a, Edit $b): int => $a->from <=> $b->from ?: $a->to <=> $b->to); + \usort($ed, static fn(Edit $a, Edit $b): int => $a->from <=> $b->from ?: $a->to <=> $b->to); // units rewritten since the parse (gaps, token texts); every other unit is still its byte range of the original code $dirty = []; foreach ($this->changed as $g) { @@ -486,7 +486,7 @@ public function rebuild(): Source return $this; } $ed = $this->edits; - \usort($ed, static fn (Edit $a, Edit $b): int => $a->from <=> $b->from ?: $a->to <=> $b->to); + \usort($ed, static fn(Edit $a, Edit $b): int => $a->from <=> $b->from ?: $a->to <=> $b->to); $code = $this->render(); $this->edits = []; if ($code === $this->join()) { diff --git a/src/Stats.php b/src/Stats.php index 5c3c30c..60107d6 100644 --- a/src/Stats.php +++ b/src/Stats.php @@ -58,12 +58,12 @@ public static function collect(array $results, int $total, float $wall, float $c } $s->skipped = \max(0, $total - \count($results)); $names = \array_keys($rules); - \usort($names, static fn (string $a, string $b): int => $rules[$b] <=> $rules[$a] ?: \strcmp($a, $b)); + \usort($names, static fn(string $a, string $b): int => $rules[$b] <=> $rules[$a] ?: \strcmp($a, $b)); foreach (\array_slice($names, 0, 10) as $n) { $s->rules[$n] = $rules[$n]; } $paths = \array_keys($times); - \usort($paths, static fn (string $a, string $b): int => $times[$b] <=> $times[$a] ?: \strcmp($a, $b)); + \usort($paths, static fn(string $a, string $b): int => $times[$b] <=> $times[$a] ?: \strcmp($a, $b)); foreach (\array_slice($paths, 0, 5) as $p) { $s->slowest[$p] = $times[$p]; } @@ -106,12 +106,17 @@ public function toArray(): array public function text(bool $color): string { - $h = static fn (string $t): string => Ansi::paint($color, Ansi::BOLD, $t); + $h = static fn(string $t): string => Ansi::paint($color, Ansi::BOLD, $t); $out = "\n" . $h('Statistics') . "\n"; - $out .= \sprintf(" files %d total, %s, %s, %s, %d skipped, %s\n", $this->total, - Ansi::paint($color, Ansi::YELLOW, $this->changed . ' changed'), Ansi::paint($color, Ansi::GREEN, $this->ok . ' ok'), - Ansi::paint($color, Ansi::DIM, $this->cached . ' cached'), $this->skipped, - Ansi::paint($color && $this->errors > 0, Ansi::RED, $this->errors . ' errors')); + $out .= \sprintf( + " files %d total, %s, %s, %s, %d skipped, %s\n", + $this->total, + Ansi::paint($color, Ansi::YELLOW, $this->changed . ' changed'), + Ansi::paint($color, Ansi::GREEN, $this->ok . ' ok'), + Ansi::paint($color, Ansi::DIM, $this->cached . ' cached'), + $this->skipped, + Ansi::paint($color && $this->errors > 0, Ansi::RED, $this->errors . ' errors'), + ); $out .= \sprintf(" time %.3f s wall%s\n", $this->wall, $this->cpu < 0.0 ? '' : \sprintf(', %.3f s cpu', $this->cpu)); $out .= \sprintf(" memory %.2f MB peak (main process)%s\n", $this->peakMb, $this->workerPeakMb > 0.0 ? \sprintf(', %.2f MB peak (largest worker)', $this->workerPeakMb) : ''); $out .= \sprintf(" throughput %.1f files/s, %.2f MB/s (%.2f MB read)\n", $this->filesPerSec(), $this->mbPerSec(), $this->bytes / 1048576); diff --git a/src/SymRules.php b/src/SymRules.php index c5b6875..b31c688 100644 --- a/src/SymRules.php +++ b/src/SymRules.php @@ -168,8 +168,12 @@ public static function make(string $name, string $lineEnding, array $opt = [], s if ($name === 'no_trailing_comma_in_singleline') { Rules::only($name, $opt, ['elements']); $el = Rules::subset($name, $opt, 'elements', ['arguments', 'array', 'array_destructuring', 'group_import'], ['arguments', 'array', 'array_destructuring', 'group_import']); - return new NoTrailingCommaInSingleline(\in_array('arguments', $el, true), \in_array('array', $el, true), \in_array('array_destructuring', $el, true), - \in_array('group_import', $el, true)); + return new NoTrailingCommaInSingleline( + \in_array('arguments', $el, true), + \in_array('array', $el, true), + \in_array('array_destructuring', $el, true), + \in_array('group_import', $el, true), + ); } if ($name === 'semicolon_after_instruction') { return new SemicolonAfterInstruction(); @@ -362,9 +366,11 @@ public static function make(string $name, string $lineEnding, array $opt = [], s } if ($name === 'string_implicit_backslashes') { Rules::only($name, $opt, ['single_quoted', 'double_quoted', 'heredoc']); - return new StringImplicitBackslashes(Rules::enum($name, $opt, 'single_quoted', ['escape', 'unescape', 'ignore'], 'unescape'), + return new StringImplicitBackslashes( + Rules::enum($name, $opt, 'single_quoted', ['escape', 'unescape', 'ignore'], 'unescape'), Rules::enum($name, $opt, 'double_quoted', ['escape', 'unescape', 'ignore'], 'escape'), - Rules::enum($name, $opt, 'heredoc', ['escape', 'unescape', 'ignore'], 'escape')); + Rules::enum($name, $opt, 'heredoc', ['escape', 'unescape', 'ignore'], 'escape'), + ); } if ($name === 'self_static_accessor') { return new SelfStaticAccessor(); diff --git a/src/TypeWalk.php b/src/TypeWalk.php index c759d5b..54538fc 100644 --- a/src/TypeWalk.php +++ b/src/TypeWalk.php @@ -12,9 +12,7 @@ */ final class TypeWalk { - public function __construct(public FlatTokens $t) - { - } + public function __construct(public FlatTokens $t) {} public function k(int $q): int { diff --git a/tests/main.php b/tests/main.php index eaa415b..021dad4 100644 --- a/tests/main.php +++ b/tests/main.php @@ -249,7 +249,7 @@ function owners(string $code): string check(fmt("preParse("\xEF\xBB\xBF Rules::make($n, "\n"), ['lowercase_keywords', 'constant_case', 'no_space_around_double_colon', +check(\count(Engine::groups(Engine::sort(\array_map(static fn(string $n): GapRule => Rules::make($n, "\n"), ['lowercase_keywords', 'constant_case', 'no_space_around_double_colon', 'spaces_inside_parentheses', 'return_type_declaration', 'types_spaces'])))) === 1, 'text and gap rules fuse into one pass'); $s = Source::parse("\n", ['no_closing_tag', 'single_blank_line_at_eof']) === " false, 'import_constants' => false, 'import_functions' => false]) +check($fmtWith( + " false, 'import_constants' => false, 'import_functions' => false], +) === " Progress::render(1234, 5678, 12.5, 100, 1000, 100, 3, false, $w); +$fit = static fn(int $w): string => Progress::render(1234, 5678, 12.5, 100, 1000, 100, 3, false, $w); check($fit(0) === '[####----------------] 1234/5678 21% 98.7 files/s ETA 46s ok 1000 changed 100 cached 100 errors 3', 'progress: width 0 = unlimited: ' . $fit(0)); check($fit(0) === $fit(200) && $fit(200) !== '', 'progress: wide enough = full'); $ok = true;