diff --git a/doc/list.rst b/doc/list.rst index c0a4d392c32..fddd71033ea 100644 --- a/doc/list.rst +++ b/doc/list.rst @@ -2174,6 +2174,8 @@ List of Available Rules | Default value: ``false`` + Part of rule set `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_ + `Source PhpCsFixer\\Fixer\\ClassNotation\\OrderedTypesFixer <./../src/Fixer/ClassNotation/OrderedTypesFixer.php>`_ - `phpdoc_add_missing_param_annotation <./rules/phpdoc/phpdoc_add_missing_param_annotation.rst>`_ diff --git a/doc/ruleSets/PhpCsFixer.rst b/doc/ruleSets/PhpCsFixer.rst index be8dcc07569..6e861ab6de0 100644 --- a/doc/ruleSets/PhpCsFixer.rst +++ b/doc/ruleSets/PhpCsFixer.rst @@ -47,6 +47,7 @@ Rules - `no_useless_else <./../rules/control_structure/no_useless_else.rst>`_ - `no_useless_return <./../rules/return_notation/no_useless_return.rst>`_ - `ordered_class_elements <./../rules/class_notation/ordered_class_elements.rst>`_ +- `ordered_types <./../rules/class_notation/ordered_types.rst>`_ - `php_unit_internal_class <./../rules/php_unit/php_unit_internal_class.rst>`_ - `php_unit_test_class_requires_covers <./../rules/php_unit/php_unit_test_class_requires_covers.rst>`_ - `phpdoc_add_missing_param_annotation <./../rules/phpdoc/phpdoc_add_missing_param_annotation.rst>`_ diff --git a/doc/rules/class_notation/ordered_types.rst b/doc/rules/class_notation/ordered_types.rst index 2b4f946acd5..423361b40ef 100644 --- a/doc/rules/class_notation/ordered_types.rst +++ b/doc/rules/class_notation/ordered_types.rst @@ -106,3 +106,11 @@ With configuration: ``['sort_algorithm' => 'none', 'null_adjustment' => 'always_ - public function bar(null|string|int $foo): string|int; + public function bar(string|int|null $foo): string|int; } + +Rule sets +--------- + +The rule is part of the following rule set: + +- `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ + diff --git a/src/Linter/TokenizerLinter.php b/src/Linter/TokenizerLinter.php index 01ec0371296..b0920d302ee 100644 --- a/src/Linter/TokenizerLinter.php +++ b/src/Linter/TokenizerLinter.php @@ -49,7 +49,7 @@ public function lintSource(string $source): LintingResultInterface Tokens::fromCode($source); return new TokenizerLintingResult(); - } catch (\ParseError|\CompileError $e) { + } catch (\CompileError|\ParseError $e) { return new TokenizerLintingResult($e); } } diff --git a/src/RuleSet/Sets/PhpCsFixerSet.php b/src/RuleSet/Sets/PhpCsFixerSet.php index 0bd66ffe137..f9fa314f87e 100644 --- a/src/RuleSet/Sets/PhpCsFixerSet.php +++ b/src/RuleSet/Sets/PhpCsFixerSet.php @@ -104,6 +104,7 @@ public function getRules(): array 'no_useless_return' => true, 'nullable_type_declaration_for_default_null_value' => false, 'ordered_class_elements' => true, + 'ordered_types' => true, 'php_unit_internal_class' => true, 'php_unit_test_class_requires_covers' => true, 'phpdoc_add_missing_param_annotation' => true, diff --git a/tests/Fixtures/Integration/misc/PHP8_0.test b/tests/Fixtures/Integration/misc/PHP8_0.test index b3f9aa1622a..abc1c678f70 100644 --- a/tests/Fixtures/Integration/misc/PHP8_0.test +++ b/tests/Fixtures/Integration/misc/PHP8_0.test @@ -52,14 +52,14 @@ $object = new #[ExampleAttribute] class() { // https://wiki.php.net/rfc/union_types_v2 class Number { - private int|float|null $number; + private null|float|int $number; - public function setNumber(int|float $number): void + public function setNumber(float|int $number): void { $this->number = $number; } - public function getNumber(): int|float|null + public function getNumber(): null|float|int { return $this->number; } diff --git a/tests/Fixtures/Integration/misc/PHP8_2.test b/tests/Fixtures/Integration/misc/PHP8_2.test index b8b923c5c0a..2e2c2343d79 100644 --- a/tests/Fixtures/Integration/misc/PHP8_2.test +++ b/tests/Fixtures/Integration/misc/PHP8_2.test @@ -96,7 +96,7 @@ trait WithConstants } // https://wiki.php.net/rfc/dnf_types -function generateSlug((HasTitle&HasId)|null $post) +function generateSlug(null|(HasId&HasTitle) $post) { throw new \Exception('not implemented'); }