
Rule ordered_types
ΒΆ
Sort union types and intersection types using configured order.
ConfigurationΒΆ
case_sensitive
ΒΆ
Whether the sorting should be case sensitive.
Allowed types: bool
Default value: false
null_adjustment
ΒΆ
Forces the position of null
(overrides sort_algorithm
).
Allowed values: 'always_first'
, 'always_last'
and 'none'
Default value: 'always_first'
sort_algorithm
ΒΆ
Whether the types should be sorted alphabetically, or not sorted.
Allowed values: 'alpha'
and 'none'
Default value: 'alpha'
ExamplesΒΆ
Example #1ΒΆ
Default configuration.
--- Original
+++ New
<?php
try {
cache()->save($foo);
-} catch (\RuntimeException|CacheException $e) {
+} catch (CacheException|\RuntimeException $e) {
logger($e);
throw $e;
}
Example #2ΒΆ
With configuration: ['case_sensitive' => true]
.
--- Original
+++ New
<?php
interface Foo
{
- public function bar(\Aaa|\AA $foo): string|int;
+ public function bar(\AA|\Aaa $foo): int|string;
}
Example #3ΒΆ
With configuration: ['null_adjustment' => 'always_last']
.
--- Original
+++ New
<?php
interface Foo
{
- public function bar(null|string|int $foo): string|int;
+ public function bar(int|string|null $foo): int|string;
- public function foo(\Stringable&\Countable $obj): int;
+ public function foo(\Countable&\Stringable $obj): int;
}
Example #4ΒΆ
With configuration: ['sort_algorithm' => 'none', 'null_adjustment' => 'always_last']
.
--- Original
+++ New
<?php
interface Bar
{
- 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: