-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Introduce
NullableTypeDeclarationFixer
(#7002)
- Loading branch information
1 parent
d7b5c39
commit f503187
Showing
15 changed files
with
798 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
doc/rules/language_construct/nullable_type_declaration.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
================================== | ||
Rule ``nullable_type_declaration`` | ||
================================== | ||
|
||
Nullable single type declaration should be standardised using configured syntax. | ||
|
||
Configuration | ||
------------- | ||
|
||
``syntax`` | ||
~~~~~~~~~~ | ||
|
||
Whether to use question mark (``?``) or explicit ``null`` union for nullable | ||
type. | ||
|
||
Allowed values: ``'question_mark'`` and ``'union'`` | ||
|
||
Default value: ``'question_mark'`` | ||
|
||
Examples | ||
-------- | ||
|
||
Example #1 | ||
~~~~~~~~~~ | ||
|
||
*Default* configuration. | ||
|
||
.. code-block:: diff | ||
--- Original | ||
+++ New | ||
<?php | ||
-function bar(null|int $value, null|\Closure $callable): void {} | ||
+function bar(?int $value, ?\Closure $callable): void {} | ||
Example #2 | ||
~~~~~~~~~~ | ||
|
||
With configuration: ``['syntax' => 'union']``. | ||
|
||
.. code-block:: diff | ||
--- Original | ||
+++ New | ||
<?php | ||
-function baz(?int $value, ?\stdClass $obj, ?array $config): ?int {} | ||
+function baz(null|int $value, null|\stdClass $obj, null|array $config): null|int {} | ||
Example #3 | ||
~~~~~~~~~~ | ||
|
||
With configuration: ``['syntax' => 'question_mark']``. | ||
|
||
.. code-block:: diff | ||
--- Original | ||
+++ New | ||
<?php | ||
class ValueObject | ||
{ | ||
- public null|string $name; | ||
+ public ?string $name; | ||
public ?int $count; | ||
- public null|bool $internal; | ||
- public null|\Closure $callback; | ||
+ public ?bool $internal; | ||
+ public ?\Closure $callback; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.