Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #4592 PhpdocToPropertyTypeFixer - introduction (julienfalque)
This PR was merged into the 2.19-dev branch. Discussion ---------- PhpdocToPropertyTypeFixer - introduction This PR includes #4591 and depends on #4593 which should both be merged first. Commits ------- 0382be5 PhpdocToPropertyTypeFixer - introduction
- Loading branch information
Showing
17 changed files
with
836 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
================================ | ||
Rule ``phpdoc_to_property_type`` | ||
================================ | ||
|
||
EXPERIMENTAL: Takes ``@var`` annotation of non-mixed types and adjusts | ||
accordingly the property signature. Requires PHP >= 7.4. | ||
|
||
.. warning:: Using this rule is risky. | ||
|
||
This rule is EXPERIMENTAL and [1] is not covered with backward compatibility | ||
promise. [2] ``@var`` annotation is mandatory for the fixer to make changes, | ||
signatures of properties without it (no docblock) will not be fixed. [3] | ||
Manual actions might be required for newly typed properties that are read | ||
before initialization. | ||
|
||
Configuration | ||
------------- | ||
|
||
``scalar_types`` | ||
~~~~~~~~~~~~~~~~ | ||
|
||
Fix also scalar types; may have unexpected behaviour due to PHP bad type | ||
coercion system. | ||
|
||
Allowed types: ``bool`` | ||
|
||
Default value: ``true`` | ||
|
||
Examples | ||
-------- | ||
|
||
Example #1 | ||
~~~~~~~~~~ | ||
|
||
*Default* configuration. | ||
|
||
.. code-block:: diff | ||
--- Original | ||
+++ New | ||
<?php | ||
class Foo { | ||
/** @var int */ | ||
- private $foo; | ||
+ private int $foo; | ||
/** @var \Traversable */ | ||
- private $bar; | ||
+ private \Traversable $bar; | ||
} | ||
Example #2 | ||
~~~~~~~~~~ | ||
|
||
With configuration: ``['scalar_types' => false]``. | ||
|
||
.. code-block:: diff | ||
--- Original | ||
+++ New | ||
<?php | ||
class Foo { | ||
/** @var int */ | ||
private $foo; | ||
/** @var \Traversable */ | ||
- private $bar; | ||
+ private \Traversable $bar; | ||
} |
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
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
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.