mirror of https://github.com/rectorphp/rector.git
Compare commits
355 Commits
Author | SHA1 | Date |
---|---|---|
Tomas Votruba | 4cadabfe9a | |
Tomas Votruba | 3f56884569 | |
Tomas Votruba | 22d3d1949d | |
Tomas Votruba | 62a900a1c0 | |
Tomas Votruba | b98d0a8754 | |
Tomas Votruba | 7ac6f7bf7e | |
Tomas Votruba | 556509e2dc | |
Tomas Votruba | dfaafdbd3a | |
Tomas Votruba | dd1dd510f5 | |
Tomas Votruba | c6998bfca9 | |
Tomas Votruba | 264e16fdae | |
Tomas Votruba | 1931c635c0 | |
Tomas Votruba | df8a377557 | |
Tomas Votruba | 6372b90b19 | |
Tomas Votruba | 6cf705918e | |
Tomas Votruba | 3c1e41f006 | |
Tomas Votruba | 7d70c5853e | |
Tomas Votruba | 049336a81a | |
Tomas Votruba | efe89cff77 | |
Tomas Votruba | 89f91b63be | |
Tomas Votruba | 5dfd1c664c | |
Tomas Votruba | 4bcc8bbea0 | |
Tomas Votruba | faba2d1971 | |
Tomas Votruba | c74c9ca74f | |
Tomas Votruba | b5b172a4b9 | |
Tomas Votruba | 49d837e2a6 | |
Tomas Votruba | af81b5db1b | |
Tomas Votruba | 5ca50de6b7 | |
Tomas Votruba | efb3c476c7 | |
Tomas Votruba | 73eb63e4f9 | |
Tomas Votruba | 322f3ad55c | |
Tomas Votruba | fe891363d5 | |
Tomas Votruba | f7723ed647 | |
Tomas Votruba | ed1310b8dc | |
Tomas Votruba | 9da012cd97 | |
Tomas Votruba | dcdff77130 | |
Tomas Votruba | 582a864f33 | |
Tomas Votruba | 2dc9d28496 | |
Tomas Votruba | 5c55f54e78 | |
Tomas Votruba | 87c26777cb | |
Tomas Votruba | 19b93eeeab | |
Tomas Votruba | fb4bddec05 | |
Tomas Votruba | ee17c27a72 | |
Tomas Votruba | 346b5723b4 | |
Tomas Votruba | 029097acda | |
Tomas Votruba | 12c115e6f6 | |
Tomas Votruba | b70df4cb6b | |
Tomas Votruba | 78e3d54584 | |
Tomas Votruba | c747b603a3 | |
Tomas Votruba | aff937886f | |
Tomas Votruba | 343a691722 | |
Tomas Votruba | e9ca0b2469 | |
Tomas Votruba | 7141ae6e56 | |
Tomas Votruba | d5e203a6e9 | |
Tomas Votruba | a3b725126c | |
Tomas Votruba | 09acbdda13 | |
Tomas Votruba | fdfd07f062 | |
Tomas Votruba | c041415e42 | |
Tomas Votruba | 3e1d355024 | |
Tomas Votruba | 6cbc8ec497 | |
Tomas Votruba | 1c323223b2 | |
Tomas Votruba | 655c2aa498 | |
Tomas Votruba | 584e892a51 | |
Tomas Votruba | b9839a24cb | |
Tomas Votruba | 1e8aeb3de9 | |
Tomas Votruba | 8aefc5e967 | |
Tomas Votruba | 6db496ec6b | |
Tomas Votruba | 24418026e3 | |
Tomas Votruba | e01fd7276e | |
Tomas Votruba | 61037dab6c | |
Tomas Votruba | f42da12667 | |
Tomas Votruba | 83bfbc18b8 | |
Tomas Votruba | b7b08c4396 | |
Tomas Votruba | 4f94d24171 | |
Tomas Votruba | 59f76a0fe3 | |
Tomas Votruba | ea0464beb9 | |
Tomas Votruba | f3e4fee4bc | |
Tomas Votruba | 284531ceed | |
Tomas Votruba | 2b9acd03a1 | |
Tomas Votruba | 885a3f6ed3 | |
Tomas Votruba | 7d4734bb64 | |
Tomas Votruba | 7f89a08ca2 | |
Tomas Votruba | 51fa5a731d | |
Tomas Votruba | 3a03381bf8 | |
Tomas Votruba | 6059061e25 | |
Tomas Votruba | f2cac5e2a0 | |
Tomas Votruba | 76a58d63f0 | |
Tomas Votruba | 0c2b95ea62 | |
Tomas Votruba | f53efcffe8 | |
Tomas Votruba | 67791a9582 | |
Tomas Votruba | 9427cdb84c | |
Tomas Votruba | d495dc4fe7 | |
Tomas Votruba | e56fb5adb0 | |
Tomas Votruba | 415f0bbf34 | |
Tomas Votruba | 8fba5b95f7 | |
Tomas Votruba | 53fb366ec6 | |
Tomas Votruba | 6fb3352189 | |
Tomas Votruba | 530c01c201 | |
Tomas Votruba | 707e3d8942 | |
Tomas Votruba | b8bbd024cd | |
Tomas Votruba | 6678ca05d4 | |
Tomas Votruba | 6e04d0eb08 | |
Tomas Votruba | d59efe6a88 | |
Tomas Votruba | e004423e08 | |
Tomas Votruba | f81fa92915 | |
Tomas Votruba | d36c8ad1a5 | |
Tomas Votruba | b352c8473a | |
Tomas Votruba | 6e65fef1e7 | |
Tomas Votruba | 81fd362a59 | |
Tomas Votruba | a210882e56 | |
Tomas Votruba | 77aab2e2a3 | |
Tomas Votruba | d4fd813b33 | |
Tomas Votruba | 36ab30b476 | |
Tomas Votruba | 3fdaba944f | |
Tomas Votruba | dc2feca4d5 | |
Tomas Votruba | 717507e265 | |
Tomas Votruba | 9f2e48fa07 | |
Tomas Votruba | bc02e10427 | |
Tomas Votruba | dc2205094c | |
Tomas Votruba | 664f4e3a6b | |
Tomas Votruba | 755e0f4a8c | |
Tomas Votruba | 9369a862b6 | |
Tomas Votruba | 9b731daab1 | |
Tomas Votruba | 0a7d532276 | |
Tomas Votruba | f2feb272ed | |
Tomas Votruba | 42078c4127 | |
Tomas Votruba | 7af3ed15e0 | |
Tomas Votruba | 30adaf3fc0 | |
Tomas Votruba | c23b2384d3 | |
Tomas Votruba | e538a96c9b | |
Tomas Votruba | 045db2fd56 | |
Tomas Votruba | 014254f0df | |
Tomas Votruba | 4c2b400cdb | |
Tomas Votruba | cc37bbf217 | |
Tomas Votruba | be393d497b | |
Tomas Votruba | 078e4b92d7 | |
Tomas Votruba | ca1cc37af8 | |
Tomas Votruba | 5d8e196d67 | |
Tomas Votruba | 52addb1dde | |
Tomas Votruba | e14c8a528b | |
Tomas Votruba | bb8b99d70c | |
Tomas Votruba | 0e57251e46 | |
Tomas Votruba | e18e5ef364 | |
Tomas Votruba | 74b8ed7cd4 | |
Tomas Votruba | e6bfc79aa2 | |
Tomas Votruba | 024ebc62a1 | |
Tomas Votruba | e10d636f62 | |
Tomas Votruba | ce9cc3aafc | |
Tomas Votruba | dd51f7ceed | |
Tomas Votruba | 11b9220a05 | |
Tomas Votruba | 9811962c70 | |
Tomas Votruba | de2b2cf2b4 | |
Tomas Votruba | 1a710b92cc | |
Tomas Votruba | c1338c4c07 | |
Tomas Votruba | 50c2e61f1d | |
Tomas Votruba | 7a69e542ca | |
Tomas Votruba | c950e4d97b | |
Tomas Votruba | 00697fa4b6 | |
Tomas Votruba | 817ab2f7cb | |
Tomas Votruba | b38b8f3e85 | |
Tomas Votruba | e94ff85194 | |
Tomas Votruba | 5ac9de7a83 | |
Tomas Votruba | ceff1cad27 | |
Tomas Votruba | ac990f2560 | |
Tomas Votruba | dac0717196 | |
Tomas Votruba | d028a05e61 | |
Tomas Votruba | b1eb18f499 | |
Tomas Votruba | 0268ca2b1c | |
Tomas Votruba | 8d1aee03a3 | |
Tomas Votruba | 51090bc214 | |
Tomas Votruba | b50605a40a | |
Tomas Votruba | 2bf9bab235 | |
Tomas Votruba | 29535d04eb | |
Tomas Votruba | dd371cdca2 | |
Tomas Votruba | d5d197b9bf | |
Tomas Votruba | 9ab2b8bc07 | |
Tomas Votruba | ae50c0e5a3 | |
Tomas Votruba | d3357ab3eb | |
Tomas Votruba | c0820093ad | |
Tomas Votruba | edd8901ea0 | |
Tomas Votruba | d7faacd4a0 | |
Tomas Votruba | c59507a909 | |
Tomas Votruba | e293557ea0 | |
Tomas Votruba | ea97f93f74 | |
Tomas Votruba | d9fea10f3e | |
Tomas Votruba | 03f122a600 | |
Tomas Votruba | 4be56b3640 | |
Tomas Votruba | 3e8c19254e | |
Tomas Votruba | ecd615137e | |
Tomas Votruba | 7660d5730f | |
Tomas Votruba | 4026ff15b0 | |
Tomas Votruba | 8201d0fc9b | |
Tomas Votruba | d8f1371a76 | |
Tomas Votruba | 0b4029ea85 | |
Tomas Votruba | 2ede0d9e01 | |
Tomas Votruba | d018e755ec | |
Tomas Votruba | 309ceb4ee6 | |
Tomas Votruba | 28f5dbde13 | |
Tomas Votruba | 2e30301381 | |
Tomas Votruba | a9ac2b236c | |
Tomas Votruba | d1ec79d324 | |
Tomas Votruba | 2c9529a881 | |
Tomas Votruba | a49cabd869 | |
Tomas Votruba | 95d5fad617 | |
Tomas Votruba | 7da00fc128 | |
Tomas Votruba | 5cc97f5690 | |
Tomas Votruba | bd3297e237 | |
Tomas Votruba | ff1845ce1a | |
Tomas Votruba | daa84a6ddf | |
Tomas Votruba | ae1f64a7a0 | |
Tomas Votruba | b05ad66b87 | |
Tomas Votruba | de9745c9cb | |
Tomas Votruba | bd2820567f | |
Tomas Votruba | 9c449858d7 | |
Tomas Votruba | 6fc08102f7 | |
Tomas Votruba | 105d14818d | |
Tomas Votruba | 4fdf5d4ab4 | |
Tomas Votruba | 7596fa6da0 | |
Tomas Votruba | 3a69e0ff7b | |
Tomas Votruba | 769ac36c32 | |
Tomas Votruba | c34bb45766 | |
Tomas Votruba | 659d1a42fb | |
Tomas Votruba | 1dbac6e2a3 | |
Tomas Votruba | 6986e1fbdb | |
Tomas Votruba | d31429d029 | |
Tomas Votruba | 991980cf2b | |
Tomas Votruba | 695c190be3 | |
Tomas Votruba | 39c0390278 | |
Tomas Votruba | df81c907da | |
Tomas Votruba | 42b37a76a2 | |
Tomas Votruba | e7800d7a95 | |
Tomas Votruba | dc6d59d8bb | |
Tomas Votruba | d148fa379c | |
Tomas Votruba | e8cdd78f11 | |
Tomas Votruba | 4da7518a07 | |
Tomas Votruba | d24ee522ce | |
Tomas Votruba | d34d554ada | |
Tomas Votruba | a958e6bf2a | |
Tomas Votruba | 3240f9e962 | |
Tomas Votruba | 740fedd8a5 | |
Tomas Votruba | b02be823eb | |
Tomas Votruba | cd427d527e | |
Tomas Votruba | dcd788c4dd | |
Tomas Votruba | 94501442a5 | |
Tomas Votruba | 5f3655eae9 | |
Tomas Votruba | c0bc2824b0 | |
Tomas Votruba | e08ae92529 | |
Tomas Votruba | 5c2a81061c | |
Tomas Votruba | 08cec1591e | |
Tomas Votruba | adbf03fcec | |
Tomas Votruba | e8568e6d97 | |
Tomas Votruba | 9ae89c0674 | |
Tomas Votruba | 283153802a | |
Tomas Votruba | dc98feb11d | |
Tomas Votruba | d7100344be | |
Tomas Votruba | 194c0359f1 | |
Tomas Votruba | c6cecac9f8 | |
Tomas Votruba | 4461c6c31d | |
Tomas Votruba | bf8ee68288 | |
Tomas Votruba | 7569719db8 | |
Tomas Votruba | 1281d2f6ab | |
Tomas Votruba | c2f97b2f3a | |
Tomas Votruba | 7105619218 | |
Tomas Votruba | 8cf7f785b6 | |
Tomas Votruba | e68f6c257d | |
Tomas Votruba | a8232e0579 | |
Tomas Votruba | d9e08f8aaf | |
Tomas Votruba | 35b646559b | |
Tomas Votruba | 6c843cb4e4 | |
Tomas Votruba | b3c461facb | |
Tomas Votruba | 2f5015d654 | |
Tomas Votruba | abeac2bdf6 | |
Tomas Votruba | 30b36b6a9d | |
Tomas Votruba | 476bd88e73 | |
Tomas Votruba | 531af37084 | |
Tomas Votruba | 95d40d3a99 | |
Tomas Votruba | f1e807548e | |
Tomas Votruba | 7a0ac36084 | |
Tomas Votruba | 718d430b73 | |
Tomas Votruba | 0d8881ecb3 | |
Tomas Votruba | 258b775511 | |
Tomas Votruba | faf7fee8e4 | |
Tomas Votruba | 6ef7f81fc3 | |
Tomas Votruba | 53742c371b | |
Tomas Votruba | b0b2790db0 | |
Tomas Votruba | 8e5eb93b0b | |
Tomas Votruba | 055cd31f66 | |
Tomas Votruba | a022b931b8 | |
Tomas Votruba | 51ddee6f5c | |
Tomas Votruba | 64ecb6b387 | |
Tomas Votruba | d85a9f8be0 | |
Tomas Votruba | adf6cdfc87 | |
Tomas Votruba | b9e54635e9 | |
Tomas Votruba | f863e8b003 | |
Tomas Votruba | 1bea0c9d65 | |
Tomas Votruba | c64634c7d7 | |
Tomas Votruba | 37b8c7c87c | |
Tomas Votruba | d1ca847d5b | |
Tomas Votruba | 1d666f3abf | |
Tomas Votruba | a120574816 | |
Tomas Votruba | 360f068804 | |
Tomas Votruba | 7cbf0706f9 | |
Tomas Votruba | 18992ab52d | |
Tomas Votruba | ae1e3ab8ca | |
Tomas Votruba | b2e06f0820 | |
Tomas Votruba | a14ff93dec | |
Tomas Votruba | 06f50472a3 | |
Tomas Votruba | b8be29526e | |
Tomas Votruba | de79e08a92 | |
Tomas Votruba | 12e1b38e32 | |
Tomas Votruba | 1d69b60457 | |
Tomas Votruba | 69e22c50fb | |
Tomas Votruba | 7f9bb2ae80 | |
Tomas Votruba | 1e3b11c5e1 | |
Tomas Votruba | 6f6fad7878 | |
Tomas Votruba | 74eb099cdd | |
Tomas Votruba | 3899caefbf | |
Tomas Votruba | f2b6b79e92 | |
Tomas Votruba | 54904b716f | |
Tomas Votruba | 7004efd93b | |
Tomas Votruba | 5e3115386a | |
Tomas Votruba | f63718b5ba | |
Tomas Votruba | b9b210cd79 | |
Tomas Votruba | bbbbb87f7d | |
Tomas Votruba | 5d5a36456b | |
Tomas Votruba | a0a66ea1c7 | |
Tomas Votruba | 3f928476d9 | |
Tomas Votruba | e32eadddc1 | |
Tomas Votruba | e5f35d1a39 | |
Tomas Votruba | 512a9f7130 | |
Tomas Votruba | 831bb7a9f7 | |
Tomas Votruba | e79510ae2b | |
Tomas Votruba | dfd0ac8201 | |
Tomas Votruba | e6361d01dc | |
Tomas Votruba | a1bb85c575 | |
Tomas Votruba | dad2c8e74c | |
Tomas Votruba | 80c79c976b | |
Tomas Votruba | 7bb5d0c0c4 | |
Tomas Votruba | af18c3962f | |
Tomas Votruba | 0d0320e989 | |
Tomas Votruba | ed0dadf714 | |
Tomas Votruba | 914c0a8e27 | |
Tomas Votruba | 4483663a95 | |
Tomas Votruba | 9d4b461bdb | |
Tomas Votruba | 1cd18a76ae | |
Tomas Votruba | c65d65d663 | |
Tomas Votruba | 362258a1f6 | |
Tomas Votruba | 64d401b643 | |
Tomas Votruba | 428336c22c | |
Tomas Votruba | d00ebb838c | |
Tomas Votruba | de3b3bb159 | |
Tomas Votruba | a5294370bd | |
Tomas Votruba | 8be4b973f1 | |
Tomas Votruba | 7810dc2e74 | |
Tomas Votruba | ad50de3844 |
|
@ -10,7 +10,7 @@ about: Report errors and problems
|
|||
|
||||
| Subject | Details |
|
||||
| :------------- | :---------------------------------------------------------------|
|
||||
| Rector version | e.g. v0.19.5 (invoke `vendor/bin/rector --version`) |
|
||||
| Rector version | e.g. v1.0.0 (invoke `vendor/bin/rector --version`) |
|
||||
|
||||
<!-- Please describe your problem here. -->
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ git clone git@github.com:<your-name>/rector-src.git
|
|||
cd rector-src
|
||||
```
|
||||
|
||||
2. We use PHP 8.1 and composer
|
||||
2. We use PHP 8.2 and composer
|
||||
|
||||
Install dependencies and verify your local environment:
|
||||
|
||||
|
|
20
README.md
20
README.md
|
@ -43,19 +43,18 @@ And modify it:
|
|||
|
||||
```php
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Set\ValueObject\SetList;
|
||||
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;
|
||||
|
||||
return static function (RectorConfig $rectorConfig): void {
|
||||
return RectorConfig::configure()
|
||||
// register single rule
|
||||
$rectorConfig->rule(TypedPropertyFromStrictConstructorRector::class);
|
||||
|
||||
// here we can define, what sets of rules will be applied
|
||||
// tip: use "SetList" class to autocomplete sets with your IDE
|
||||
$rectorConfig->sets([
|
||||
SetList::CODE_QUALITY
|
||||
]);
|
||||
};
|
||||
->withRules([
|
||||
TypedPropertyFromStrictConstructorRector::class
|
||||
])
|
||||
// here we can define, what prepared sets of rules will be applied
|
||||
->withPreparedSets(
|
||||
deadCode: true,
|
||||
codeQuality: true
|
||||
);
|
||||
```
|
||||
|
||||
Then dry run Rector:
|
||||
|
@ -102,6 +101,7 @@ Among there projects belong:
|
|||
* [cakephp/upgrade](https://github.com/cakephp/upgrade)
|
||||
* [driftingly/rector-laravel](https://github.com/driftingly/rector-laravel)
|
||||
* [contao/contao-rector](https://github.com/contao/contao-rector)
|
||||
* [php-static-analysis/rector-rule](https://github.com/php-static-analysis/rector-rule)
|
||||
|
||||
<br>
|
||||
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
// this is part of downgrade build
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use RectorPrefix202402\Nette\Utils\FileSystem;
|
||||
use RectorPrefix202402\Nette\Utils\Json;
|
||||
use RectorPrefix202405\Nette\Utils\FileSystem;
|
||||
use RectorPrefix202405\Nette\Utils\Json;
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
$composerJsonFileContents = FileSystem::read(__DIR__ . '/../composer.json');
|
||||
$composerJson = Json::decode($composerJsonFileContents, Json::FORCE_ARRAY);
|
||||
$composerJson = Json::decode($composerJsonFileContents, \true);
|
||||
$composerJson['replace']['phpstan/phpstan'] = $composerJson['require']['phpstan/phpstan'];
|
||||
$modifiedComposerJsonFileContents = Json::encode($composerJson, Json::PRETTY);
|
||||
$modifiedComposerJsonFileContents = Json::encode($composerJson, \true);
|
||||
FileSystem::write(__DIR__ . '/../composer.json', $modifiedComposerJsonFileContents, null);
|
||||
echo 'Done!' . \PHP_EOL;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
require_once __DIR__ . '/rector.php';
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use RectorPrefix202402\Nette\Utils\Json;
|
||||
use RectorPrefix202405\Nette\Utils\Json;
|
||||
use Rector\Bootstrap\RectorConfigsResolver;
|
||||
use Rector\ChangesReporting\Output\JsonOutputFormatter;
|
||||
use Rector\Configuration\Option;
|
||||
|
@ -11,9 +11,9 @@ use Rector\Console\Style\SymfonyStyleFactory;
|
|||
use Rector\DependencyInjection\LazyContainerFactory;
|
||||
use Rector\DependencyInjection\RectorContainerFactory;
|
||||
use Rector\Util\Reflection\PrivatesAccessor;
|
||||
use RectorPrefix202402\Symfony\Component\Console\Application;
|
||||
use RectorPrefix202402\Symfony\Component\Console\Command\Command;
|
||||
use RectorPrefix202402\Symfony\Component\Console\Input\ArgvInput;
|
||||
use RectorPrefix202405\Symfony\Component\Console\Application;
|
||||
use RectorPrefix202405\Symfony\Component\Console\Command\Command;
|
||||
use RectorPrefix202405\Symfony\Component\Console\Input\ArgvInput;
|
||||
// @ intentionally: continue anyway
|
||||
@\ini_set('memory_limit', '-1');
|
||||
// Performance boost
|
||||
|
@ -93,7 +93,7 @@ final class AutoloadIncluder
|
|||
require_once $filePath;
|
||||
}
|
||||
}
|
||||
\class_alias('RectorPrefix202402\\AutoloadIncluder', 'AutoloadIncluder', \false);
|
||||
\class_alias('RectorPrefix202405\\AutoloadIncluder', 'AutoloadIncluder', \false);
|
||||
if (\file_exists(__DIR__ . '/../preload.php') && \is_dir(__DIR__ . '/../vendor')) {
|
||||
require_once __DIR__ . '/../preload.php';
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
],
|
||||
"require": {
|
||||
"php": "^7.2|^8.0",
|
||||
"phpstan/phpstan": "^1.10.56"
|
||||
"phpstan/phpstan": "^1.11"
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
|
@ -22,5 +22,8 @@
|
|||
"rector/rector-downgrade-php": "*"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
"prefer-stable": true,
|
||||
"suggest": {
|
||||
"ext-dom": "To manipulate phpunit.xml via the custom-rule command"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use RectorPrefix202402\OndraM\CiDetector\CiDetector;
|
||||
use RectorPrefix202405\OndraM\CiDetector\CiDetector;
|
||||
use Rector\Bootstrap\ExtensionConfigResolver;
|
||||
use Rector\Caching\ValueObject\Storage\MemoryCacheStorage;
|
||||
use Rector\Config\RectorConfig;
|
||||
|
@ -31,4 +31,6 @@ return static function (RectorConfig $rectorConfig) : void {
|
|||
foreach ($extensionConfigResolver->provide() as $extensionConfigFile) {
|
||||
$rectorConfig->import($extensionConfigFile);
|
||||
}
|
||||
// use original php-parser printer to avoid BC break on fluent call
|
||||
$rectorConfig->newLineOnFluentCall(\false);
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector;
|
||||
use Rector\CodeQuality\Rector\Assign\CombinedAssignRector;
|
||||
|
@ -12,7 +12,9 @@ use Rector\CodeQuality\Rector\BooleanNot\SimplifyDeMorganBinaryRector;
|
|||
use Rector\CodeQuality\Rector\Catch_\ThrowWithPreviousExceptionRector;
|
||||
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
|
||||
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
|
||||
use Rector\CodeQuality\Rector\Class_\StaticToSelfStaticMethodCallOnFinalClassRector;
|
||||
use Rector\CodeQuality\Rector\ClassConstFetch\ConvertStaticPrivateConstantToSelfRector;
|
||||
use Rector\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector;
|
||||
use Rector\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector;
|
||||
use Rector\CodeQuality\Rector\ClassMethod\LocallyCalledStaticMethodToNonStaticRector;
|
||||
use Rector\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector;
|
||||
|
@ -27,13 +29,10 @@ use Rector\CodeQuality\Rector\Foreach_\ForeachToInArrayRector;
|
|||
use Rector\CodeQuality\Rector\Foreach_\SimplifyForeachToCoalescingRector;
|
||||
use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\ArrayMergeOfNonArraysToSimpleArrayRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\BoolvalToTypeCastRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\CallUserFuncWithArrowFunctionToInlineRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\FloatvalToTypeCastRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\InlineIsAInstanceOfRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\IntvalToTypeCastRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\IsAWithStringWithThirdArgumentRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\RemoveSoleValueSprintfRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\SetTypeToCastRector;
|
||||
|
@ -42,7 +41,6 @@ use Rector\CodeQuality\Rector\FuncCall\SimplifyInArrayValuesRector;
|
|||
use Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\SingleInArrayToCompareRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\StrvalToTypeCastRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\UnwrapSprintfOneArgumentRector;
|
||||
use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
|
||||
use Rector\CodeQuality\Rector\Identical\BooleanNotIdenticalToNotIdenticalRector;
|
||||
|
@ -110,5 +108,5 @@ return static function (RectorConfig $rectorConfig) : void {
|
|||
'mbstrrpos' => 'mb_strrpos',
|
||||
'mbsubstr' => 'mb_substr',
|
||||
]);
|
||||
$rectorConfig->rules([CombinedAssignRector::class, SimplifyEmptyArrayCheckRector::class, ReplaceMultipleBooleanNotRector::class, ForeachToInArrayRector::class, SimplifyForeachToCoalescingRector::class, SimplifyFuncGetArgsCountRector::class, SimplifyInArrayValuesRector::class, SimplifyStrposLowerRector::class, GetClassToInstanceOfRector::class, SimplifyArraySearchRector::class, SimplifyConditionsRector::class, SimplifyIfNotNullReturnRector::class, SimplifyIfReturnBoolRector::class, SimplifyUselessVariableRector::class, UnnecessaryTernaryExpressionRector::class, RemoveExtraParametersRector::class, SimplifyDeMorganBinaryRector::class, SimplifyTautologyTernaryRector::class, SingleInArrayToCompareRector::class, SimplifyIfElseToTernaryRector::class, JoinStringConcatRector::class, ConsecutiveNullCompareReturnsToNullCoalesceQueueRector::class, ExplicitBoolCompareRector::class, CombineIfRector::class, UseIdenticalOverEqualWithSameTypeRector::class, SimplifyBoolIdenticalTrueRector::class, SimplifyRegexPatternRector::class, BooleanNotIdenticalToNotIdenticalRector::class, StrvalToTypeCastRector::class, FloatvalToTypeCastRector::class, CallableThisArrayToAnonymousFunctionRector::class, AndAssignsToSeparateLinesRector::class, CompactToVariablesRector::class, CompleteDynamicPropertiesRector::class, IsAWithStringWithThirdArgumentRector::class, StrlenZeroToIdenticalEmptyStringRector::class, ThrowWithPreviousExceptionRector::class, RemoveSoleValueSprintfRector::class, ShortenElseIfRector::class, ArrayMergeOfNonArraysToSimpleArrayRector::class, IntvalToTypeCastRector::class, BoolvalToTypeCastRector::class, ArrayKeyExistsTernaryThenValueToCoalescingRector::class, AbsolutizeRequireAndIncludePathRector::class, ChangeArrayPushToArrayAssignRector::class, ForRepeatedCountToOwnVariableRector::class, ForeachItemsAssignToEmptyArrayToAssignRector::class, InlineIfToExplicitIfRector::class, UnusedForeachValueToArrayKeysRector::class, CommonNotEqualRector::class, SetTypeToCastRector::class, LogicalToBooleanRector::class, VarToPublicPropertyRector::class, IssetOnPropertyObjectToPropertyExistsRector::class, NewStaticToNewSelfRector::class, UnwrapSprintfOneArgumentRector::class, SwitchNegatedTernaryRector::class, SingularSwitchToIfRector::class, SimplifyIfNullableReturnRector::class, FuncGetArgsToVariadicParamRector::class, CallUserFuncToMethodCallRector::class, CallUserFuncWithArrowFunctionToInlineRector::class, CountArrayToEmptyArrayComparisonRector::class, FlipTypeControlToUseExclusiveTypeRector::class, InlineArrayReturnAssignRector::class, InlineIsAInstanceOfRector::class, TernaryFalseExpressionToIfRector::class, InlineConstructorDefaultToPropertyRector::class, TernaryEmptyArrayArrayDimFetchToCoalesceRector::class, OptionalParametersAfterRequiredRector::class, SimplifyEmptyCheckOnEmptyArrayRector::class, SwitchTrueToIfRector::class, CleanupUnneededNullsafeOperatorRector::class, DisallowedEmptyRuleFixerRector::class, ConvertStaticPrivateConstantToSelfRector::class, LocallyCalledStaticMethodToNonStaticRector::class, NumberCompareToMaxFuncCallRector::class, CompleteMissingIfElseBracketRector::class, RemoveUselessIsObjectCheckRector::class]);
|
||||
$rectorConfig->rules([CombinedAssignRector::class, SimplifyEmptyArrayCheckRector::class, ReplaceMultipleBooleanNotRector::class, ForeachToInArrayRector::class, SimplifyForeachToCoalescingRector::class, SimplifyFuncGetArgsCountRector::class, SimplifyInArrayValuesRector::class, SimplifyStrposLowerRector::class, GetClassToInstanceOfRector::class, SimplifyArraySearchRector::class, SimplifyConditionsRector::class, SimplifyIfNotNullReturnRector::class, SimplifyIfReturnBoolRector::class, SimplifyUselessVariableRector::class, UnnecessaryTernaryExpressionRector::class, RemoveExtraParametersRector::class, SimplifyDeMorganBinaryRector::class, SimplifyTautologyTernaryRector::class, SingleInArrayToCompareRector::class, SimplifyIfElseToTernaryRector::class, JoinStringConcatRector::class, ConsecutiveNullCompareReturnsToNullCoalesceQueueRector::class, ExplicitBoolCompareRector::class, CombineIfRector::class, UseIdenticalOverEqualWithSameTypeRector::class, SimplifyBoolIdenticalTrueRector::class, SimplifyRegexPatternRector::class, BooleanNotIdenticalToNotIdenticalRector::class, CallableThisArrayToAnonymousFunctionRector::class, AndAssignsToSeparateLinesRector::class, CompactToVariablesRector::class, CompleteDynamicPropertiesRector::class, IsAWithStringWithThirdArgumentRector::class, StrlenZeroToIdenticalEmptyStringRector::class, ThrowWithPreviousExceptionRector::class, RemoveSoleValueSprintfRector::class, ShortenElseIfRector::class, ExplicitReturnNullRector::class, ArrayMergeOfNonArraysToSimpleArrayRector::class, ArrayKeyExistsTernaryThenValueToCoalescingRector::class, AbsolutizeRequireAndIncludePathRector::class, ChangeArrayPushToArrayAssignRector::class, ForRepeatedCountToOwnVariableRector::class, ForeachItemsAssignToEmptyArrayToAssignRector::class, InlineIfToExplicitIfRector::class, UnusedForeachValueToArrayKeysRector::class, CommonNotEqualRector::class, SetTypeToCastRector::class, LogicalToBooleanRector::class, VarToPublicPropertyRector::class, IssetOnPropertyObjectToPropertyExistsRector::class, NewStaticToNewSelfRector::class, UnwrapSprintfOneArgumentRector::class, SwitchNegatedTernaryRector::class, SingularSwitchToIfRector::class, SimplifyIfNullableReturnRector::class, FuncGetArgsToVariadicParamRector::class, CallUserFuncToMethodCallRector::class, CallUserFuncWithArrowFunctionToInlineRector::class, CountArrayToEmptyArrayComparisonRector::class, FlipTypeControlToUseExclusiveTypeRector::class, InlineArrayReturnAssignRector::class, InlineIsAInstanceOfRector::class, TernaryFalseExpressionToIfRector::class, InlineConstructorDefaultToPropertyRector::class, TernaryEmptyArrayArrayDimFetchToCoalesceRector::class, OptionalParametersAfterRequiredRector::class, SimplifyEmptyCheckOnEmptyArrayRector::class, SwitchTrueToIfRector::class, CleanupUnneededNullsafeOperatorRector::class, DisallowedEmptyRuleFixerRector::class, ConvertStaticPrivateConstantToSelfRector::class, LocallyCalledStaticMethodToNonStaticRector::class, NumberCompareToMaxFuncCallRector::class, CompleteMissingIfElseBracketRector::class, RemoveUselessIsObjectCheckRector::class, StaticToSelfStaticMethodCallOnFinalClassRector::class]);
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\CodingStyle\Rector\ArrowFunction\StaticArrowFunctionRector;
|
||||
use Rector\CodingStyle\Rector\Assign\SplitDoubleAssignRector;
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector;
|
||||
use Rector\Carbon\Rector\MethodCall\DateTimeMethodCallToCarbonRector;
|
||||
use Rector\Carbon\Rector\New_\DateTimeInstanceToCarbonRector;
|
||||
use Rector\Config\RectorConfig;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->rules([DateFuncCallToCarbonRector::class, DateTimeInstanceToCarbonRector::class, DateTimeMethodCallToCarbonRector::class]);
|
||||
};
|
|
@ -1,93 +1,10 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
|
||||
use Rector\Config\Level\DeadCodeLevel;
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\DeadCode\Rector\Array_\RemoveDuplicatedArrayKeyRector;
|
||||
use Rector\DeadCode\Rector\Assign\RemoveDoubleAssignRector;
|
||||
use Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector;
|
||||
use Rector\DeadCode\Rector\BooleanAnd\RemoveAndTrueRector;
|
||||
use Rector\DeadCode\Rector\Cast\RecastingRemovalRector;
|
||||
use Rector\DeadCode\Rector\ClassConst\RemoveUnusedPrivateClassConstantRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodParameterRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnExprInConstructRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
|
||||
use Rector\DeadCode\Rector\Concat\RemoveConcatAutocastRector;
|
||||
use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector;
|
||||
use Rector\DeadCode\Rector\Expression\RemoveDeadStmtRector;
|
||||
use Rector\DeadCode\Rector\Expression\SimplifyMirrorAssignRector;
|
||||
use Rector\DeadCode\Rector\For_\RemoveDeadContinueRector;
|
||||
use Rector\DeadCode\Rector\For_\RemoveDeadIfForeachForRector;
|
||||
use Rector\DeadCode\Rector\For_\RemoveDeadLoopRector;
|
||||
use Rector\DeadCode\Rector\Foreach_\RemoveUnusedForeachKeyRector;
|
||||
use Rector\DeadCode\Rector\FunctionLike\RemoveDeadReturnRector;
|
||||
use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
|
||||
use Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector;
|
||||
use Rector\DeadCode\Rector\If_\RemoveTypedPropertyDeadInstanceOfRector;
|
||||
use Rector\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector;
|
||||
use Rector\DeadCode\Rector\If_\SimplifyIfElseWithSameContentRector;
|
||||
use Rector\DeadCode\Rector\If_\UnwrapFutureCompatibleIfPhpVersionRector;
|
||||
use Rector\DeadCode\Rector\Node\RemoveNonExistingVarAnnotationRector;
|
||||
use Rector\DeadCode\Rector\Plus\RemoveDeadZeroAndOneOperationRector;
|
||||
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
|
||||
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
|
||||
use Rector\DeadCode\Rector\PropertyProperty\RemoveNullPropertyInitializationRector;
|
||||
use Rector\DeadCode\Rector\Return_\RemoveDeadConditionAboveReturnRector;
|
||||
use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
|
||||
use Rector\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector;
|
||||
use Rector\DeadCode\Rector\Switch_\RemoveDuplicatedCaseInSwitchRector;
|
||||
use Rector\DeadCode\Rector\Ternary\TernaryToBooleanOrFalseToBooleanAndRector;
|
||||
use Rector\DeadCode\Rector\TryCatch\RemoveDeadTryCatchRector;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->rules([
|
||||
UnwrapFutureCompatibleIfPhpVersionRector::class,
|
||||
RecastingRemovalRector::class,
|
||||
RemoveDeadStmtRector::class,
|
||||
RemoveDuplicatedArrayKeyRector::class,
|
||||
RemoveUnusedForeachKeyRector::class,
|
||||
RemoveParentCallWithoutParentRector::class,
|
||||
RemoveEmptyClassMethodRector::class,
|
||||
RemoveDoubleAssignRector::class,
|
||||
SimplifyMirrorAssignRector::class,
|
||||
RemoveUnusedPrivatePropertyRector::class,
|
||||
RemoveUnusedPrivateClassConstantRector::class,
|
||||
RemoveUnusedPrivateMethodRector::class,
|
||||
RemoveDeadReturnRector::class,
|
||||
RemoveDeadContinueRector::class,
|
||||
RemoveDeadIfForeachForRector::class,
|
||||
RemoveAndTrueRector::class,
|
||||
RemoveConcatAutocastRector::class,
|
||||
SimplifyUselessVariableRector::class,
|
||||
RemoveDuplicatedCaseInSwitchRector::class,
|
||||
RemoveNullPropertyInitializationRector::class,
|
||||
RemoveUnreachableStatementRector::class,
|
||||
SimplifyIfElseWithSameContentRector::class,
|
||||
TernaryToBooleanOrFalseToBooleanAndRector::class,
|
||||
RemoveDeadTryCatchRector::class,
|
||||
RemoveUnusedVariableAssignRector::class,
|
||||
RemoveUnusedNonEmptyArrayBeforeForeachRector::class,
|
||||
RemoveDeadConditionAboveReturnRector::class,
|
||||
RemoveUnusedConstructorParamRector::class,
|
||||
RemoveDeadInstanceOfRector::class,
|
||||
RemoveTypedPropertyDeadInstanceOfRector::class,
|
||||
RemoveDeadLoopRector::class,
|
||||
RemoveUnusedPrivateMethodParameterRector::class,
|
||||
// docblock
|
||||
RemoveUselessParamTagRector::class,
|
||||
RemoveUselessReturnTagRector::class,
|
||||
RemoveNonExistingVarAnnotationRector::class,
|
||||
RemoveUselessVarTagRector::class,
|
||||
RemoveUnusedPromotedPropertyRector::class,
|
||||
RemoveAlwaysTrueIfConditionRector::class,
|
||||
RemoveDeadZeroAndOneOperationRector::class,
|
||||
RemovePhpVersionIdCheckRector::class,
|
||||
RemoveUselessReturnExprInConstructRector::class,
|
||||
]);
|
||||
$rectorConfig->rules(DeadCodeLevel::RULES);
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\CodeQuality\Rector\FuncCall\InlineIsAInstanceOfRector;
|
||||
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Set\ValueObject\SetList;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Set\ValueObject\LevelSetList;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Set\ValueObject\LevelSetList;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Set\ValueObject\LevelSetList;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Set\ValueObject\LevelSetList;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Set\ValueObject\LevelSetList;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Set\ValueObject\LevelSetList;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Set\ValueObject\LevelSetList;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Set\ValueObject\LevelSetList;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Set\ValueObject\LevelSetList;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Set\ValueObject\LevelSetList;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Set\ValueObject\LevelSetList;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Set\ValueObject\LevelSetList;
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Set\ValueObject\LevelSetList;
|
||||
use Rector\Set\ValueObject\SetList;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->sets([SetList::PHP_84, LevelSetList::UP_TO_PHP_83]);
|
||||
};
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Php52\Rector\Property\VarToPublicPropertyRector;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Php53\Rector\FuncCall\DirNameFileConstantToDirConstantRector;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Php54\Rector\Array_\LongArrayToShortArrayRector;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Php55\Rector\Class_\ClassConstantToSelfClassRector;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Php56\Rector\FuncCall\PowToExpRector;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Php70\Rector\Assign\ListSplitStringRector;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Php71\Rector\Assign\AssignArrayToStringRector;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Php72\Rector\Assign\ListEachRector;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Php52\Rector\Switch_\ContinueToBreakInSwitchRector;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Php74\Rector\ArrayDimFetch\CurlyToSquareBracketArrayStringRector;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
|
||||
use Rector\Arguments\Rector\FuncCall\FunctionArgumentDefaultValueReplacerRector;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Php81\Rector\Array_\FirstClassCallableRector;
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Php82\Rector\Class_\ReadOnlyClassRector;
|
||||
use Rector\Php82\Rector\Encapsed\VariableInStringInterpolationFixerRector;
|
||||
use Rector\Php82\Rector\FuncCall\Utf8DecodeEncodeToMbConvertEncodingRector;
|
||||
use Rector\Php82\Rector\New_\FilesystemIteratorSkipDotsRector;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->rules([ReadOnlyClassRector::class, Utf8DecodeEncodeToMbConvertEncodingRector::class, FilesystemIteratorSkipDotsRector::class]);
|
||||
$rectorConfig->rules([ReadOnlyClassRector::class, Utf8DecodeEncodeToMbConvertEncodingRector::class, FilesystemIteratorSkipDotsRector::class, VariableInStringInterpolationFixerRector::class]);
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Php83\Rector\ClassConst\AddTypeToConstRector;
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Php84\Rector\Param\ExplicitNullableParamTypeRector;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->rules([ExplicitNullableParamTypeRector::class]);
|
||||
};
|
|
@ -1,10 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Privatization\Rector\ClassMethod\PrivatizeFinalClassMethodRector;
|
||||
use Rector\Privatization\Rector\MethodCall\PrivatizeLocalGetterToPropertyRector;
|
||||
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
|
||||
return RectorConfig::configure()->withRules([PrivatizeLocalGetterToPropertyRector::class, PrivatizeFinalClassPropertyRector::class, PrivatizeFinalClassMethodRector::class]);
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->rules([PrivatizeLocalGetterToPropertyRector::class, PrivatizeFinalClassPropertyRector::class, PrivatizeFinalClassMethodRector::class]);
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Strict\Rector\BooleanNot\BooleanInBooleanNotRuleFixerRector;
|
||||
|
|
|
@ -1,43 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202402;
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Config\Level\TypeDeclarationLevel;
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector;
|
||||
use Rector\TypeDeclaration\Rector\Class_\MergeDateTimePropertyTypeDeclarationRector;
|
||||
use Rector\TypeDeclaration\Rector\Class_\PropertyTypeFromStrictSetterGetterRector;
|
||||
use Rector\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeBasedOnPHPUnitDataProviderRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeFromPropertyTypeRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationBasedOnParentClassMethodRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\BoolReturnTypeFromStrictScalarReturnsRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\NumericReturnTypeFromStrictScalarReturnsRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByParentCallTypeRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnDirectArrayRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictBoolReturnExprRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictConstantReturnRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictFluentReturnRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNativeCallRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNewArrayRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictParamRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedPropertyRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\StrictStringParamConcatRector;
|
||||
use Rector\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector;
|
||||
use Rector\TypeDeclaration\Rector\FunctionLike\AddParamTypeSplFixedArrayRector;
|
||||
use Rector\TypeDeclaration\Rector\FunctionLike\AddReturnTypeDeclarationFromYieldsRector;
|
||||
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
|
||||
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;
|
||||
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictSetUpRector;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->rules([AddArrowFunctionReturnTypeRector::class, ParamTypeByMethodCallTypeRector::class, TypedPropertyFromAssignsRector::class, AddReturnTypeDeclarationBasedOnParentClassMethodRector::class, ReturnTypeFromStrictTypedPropertyRector::class, TypedPropertyFromStrictConstructorRector::class, AddVoidReturnTypeWhereNoReturnRector::class, ReturnTypeFromStrictFluentReturnRector::class, ReturnTypeFromReturnNewRector::class, AddMethodCallBasedStrictParamTypeRector::class, ReturnTypeFromStrictBoolReturnExprRector::class, ReturnTypeFromStrictNativeCallRector::class, ReturnTypeFromStrictNewArrayRector::class, ReturnTypeFromStrictScalarReturnExprRector::class, ReturnTypeFromStrictParamRector::class, TypedPropertyFromStrictSetUpRector::class, ParamTypeByParentCallTypeRector::class, AddParamTypeSplFixedArrayRector::class, AddParamTypeBasedOnPHPUnitDataProviderRector::class, AddParamTypeFromPropertyTypeRector::class, AddReturnTypeDeclarationFromYieldsRector::class, ReturnTypeFromReturnDirectArrayRector::class, ReturnTypeFromStrictConstantReturnRector::class, ReturnTypeFromStrictTypedCallRector::class, ReturnNeverTypeRector::class, EmptyOnNullableObjectToInstanceOfRector::class, PropertyTypeFromStrictSetterGetterRector::class, ReturnTypeFromStrictTernaryRector::class, BoolReturnTypeFromStrictScalarReturnsRector::class, NumericReturnTypeFromStrictScalarReturnsRector::class, StrictArrayParamDimFetchRector::class, ReturnUnionTypeRector::class, StrictStringParamConcatRector::class, MergeDateTimePropertyTypeDeclarationRector::class]);
|
||||
// the rule order matters, as its used in withTypeCoverageLevel() method
|
||||
// place the safest rules first, follow by more complex ones
|
||||
$rectorConfig->rules(TypeDeclarationLevel::RULES);
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# 355 Rules Overview
|
||||
# 374 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
|
@ -6,11 +6,13 @@
|
|||
|
||||
- [Arguments](#arguments) (4)
|
||||
|
||||
- [CodeQuality](#codequality) (73)
|
||||
- [Carbon](#carbon) (3)
|
||||
|
||||
- [CodeQuality](#codequality) (75)
|
||||
|
||||
- [CodingStyle](#codingstyle) (28)
|
||||
|
||||
- [DeadCode](#deadcode) (42)
|
||||
- [DeadCode](#deadcode) (44)
|
||||
|
||||
- [EarlyReturn](#earlyreturn) (9)
|
||||
|
||||
|
@ -42,21 +44,23 @@
|
|||
|
||||
- [Php81](#php81) (9)
|
||||
|
||||
- [Php82](#php82) (4)
|
||||
- [Php82](#php82) (5)
|
||||
|
||||
- [Php83](#php83) (3)
|
||||
|
||||
- [Php84](#php84) (1)
|
||||
|
||||
- [Privatization](#privatization) (5)
|
||||
|
||||
- [Removing](#removing) (5)
|
||||
|
||||
- [Renaming](#renaming) (9)
|
||||
- [Renaming](#renaming) (10)
|
||||
|
||||
- [Strict](#strict) (5)
|
||||
|
||||
- [Transform](#transform) (22)
|
||||
- [Transform](#transform) (25)
|
||||
|
||||
- [TypeDeclaration](#typedeclaration) (40)
|
||||
- [TypeDeclaration](#typedeclaration) (46)
|
||||
|
||||
- [Visibility](#visibility) (3)
|
||||
|
||||
|
@ -140,6 +144,59 @@ Replaces defined map of arguments in defined methods and their calls.
|
|||
|
||||
<br>
|
||||
|
||||
## Carbon
|
||||
|
||||
### DateFuncCallToCarbonRector
|
||||
|
||||
Convert `date()` function call to Carbon::*()
|
||||
|
||||
- class: [`Rector\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector`](../rules/Carbon/Rector/FuncCall/DateFuncCallToCarbonRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
- $date = date('Y-m-d');
|
||||
+ $date = \Carbon\Carbon::now()->format('Y-m-d')
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### DateTimeInstanceToCarbonRector
|
||||
|
||||
Convert new `DateTime()` to Carbon::*()
|
||||
|
||||
- class: [`Rector\Carbon\Rector\New_\DateTimeInstanceToCarbonRector`](../rules/Carbon/Rector/New_/DateTimeInstanceToCarbonRector.php)
|
||||
|
||||
```diff
|
||||
-$date = new \DateTime('today');
|
||||
+$date = \Carbon\Carbon::today();
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### DateTimeMethodCallToCarbonRector
|
||||
|
||||
Convert new `DateTime()` with a method call to Carbon::*()
|
||||
|
||||
- class: [`Rector\Carbon\Rector\MethodCall\DateTimeMethodCallToCarbonRector`](../rules/Carbon/Rector/MethodCall/DateTimeMethodCallToCarbonRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
- $date = (new \DateTime('today +20 day'))->format('Y-m-d');
|
||||
+ $date = \Carbon\Carbon::today()->addDays(20)->format('Y-m-d')
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## CodeQuality
|
||||
|
||||
### AbsolutizeRequireAndIncludePathRector
|
||||
|
@ -547,6 +604,32 @@ Make if conditions more explicit
|
|||
|
||||
<br>
|
||||
|
||||
### ExplicitReturnNullRector
|
||||
|
||||
Add explicit return null to method/function that returns a value, but missed main return
|
||||
|
||||
- class: [`Rector\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector`](../rules/CodeQuality/Rector/ClassMethod/ExplicitReturnNullRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
- * @return string|void
|
||||
+ * @return string|null
|
||||
*/
|
||||
public function run(int $number)
|
||||
{
|
||||
if ($number > 50) {
|
||||
return 'yes';
|
||||
}
|
||||
+
|
||||
+ return null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### FlipTypeControlToUseExclusiveTypeRector
|
||||
|
||||
Flip type control from null compare to use exclusive instanceof object
|
||||
|
@ -1352,6 +1435,30 @@ Change switch with only 1 check to if
|
|||
|
||||
<br>
|
||||
|
||||
### StaticToSelfStaticMethodCallOnFinalClassRector
|
||||
|
||||
Change `static::methodCall()` to `self::methodCall()` on final class
|
||||
|
||||
- class: [`Rector\CodeQuality\Rector\Class_\StaticToSelfStaticMethodCallOnFinalClassRector`](../rules/CodeQuality/Rector/Class_/StaticToSelfStaticMethodCallOnFinalClassRector.php)
|
||||
|
||||
```diff
|
||||
final class SomeClass
|
||||
{
|
||||
public function d()
|
||||
{
|
||||
- echo static::run();
|
||||
+ echo self::run();
|
||||
}
|
||||
|
||||
private static function run()
|
||||
{
|
||||
echo 'test';
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### StrlenZeroToIdenticalEmptyStringRector
|
||||
|
||||
Changes strlen comparison to 0 to direct empty string compare
|
||||
|
@ -2131,6 +2238,29 @@ Removes recasting of the same type
|
|||
|
||||
<br>
|
||||
|
||||
### ReduceAlwaysFalseIfOrRector
|
||||
|
||||
Reduce always false in a if ( || ) condition
|
||||
|
||||
- class: [`Rector\DeadCode\Rector\If_\ReduceAlwaysFalseIfOrRector`](../rules/DeadCode/Rector/If_/ReduceAlwaysFalseIfOrRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
public function run(int $number)
|
||||
{
|
||||
- if (! is_int($number) || $number > 50) {
|
||||
+ if ($number > 50) {
|
||||
return 'yes';
|
||||
}
|
||||
|
||||
return 'no';
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### RemoveAlwaysTrueIfConditionRector
|
||||
|
||||
Remove if condition that is always true
|
||||
|
@ -2811,6 +2941,29 @@ Remove `@param` docblock with same type as parameter type
|
|||
|
||||
<br>
|
||||
|
||||
### RemoveUselessReadOnlyTagRector
|
||||
|
||||
Remove useless `@readonly` annotation on native readonly type
|
||||
|
||||
- class: [`Rector\DeadCode\Rector\Property\RemoveUselessReadOnlyTagRector`](../rules/DeadCode/Rector/Property/RemoveUselessReadOnlyTagRector.php)
|
||||
|
||||
```diff
|
||||
final class SomeClass
|
||||
{
|
||||
- /**
|
||||
- * @readonly
|
||||
- */
|
||||
private readonly string $name;
|
||||
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### RemoveUselessReturnExprInConstructRector
|
||||
|
||||
Remove useless return Expr in `__construct()`
|
||||
|
@ -4669,9 +4822,9 @@ Change annotation to attribute
|
|||
class SymfonyRoute
|
||||
{
|
||||
- /**
|
||||
- * @Route("/path", name="action")
|
||||
- * @Route("/path", name="action") api route
|
||||
- */
|
||||
+ #[Route(path: '/path', name: 'action')]
|
||||
+ #[Route(path: '/path', name: 'action')] // api route
|
||||
public function action()
|
||||
{
|
||||
}
|
||||
|
@ -5248,6 +5401,20 @@ Change deprecated utf8_decode and utf8_encode to mb_convert_encoding
|
|||
|
||||
<br>
|
||||
|
||||
### VariableInStringInterpolationFixerRector
|
||||
|
||||
Replace deprecated "${var}" to "{$var}"
|
||||
|
||||
- class: [`Rector\Php82\Rector\Encapsed\VariableInStringInterpolationFixerRector`](../rules/Php82/Rector/Encapsed/VariableInStringInterpolationFixerRector.php)
|
||||
|
||||
```diff
|
||||
$c = "football";
|
||||
-echo "I like playing ${c}";
|
||||
+echo "I like playing {$c}";
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## Php83
|
||||
|
||||
### AddOverrideAttributeToOverriddenMethodsRector
|
||||
|
@ -5277,7 +5444,7 @@ Add override attribute to overridden methods
|
|||
|
||||
### AddTypeToConstRector
|
||||
|
||||
Add const to type
|
||||
Add type to constants
|
||||
|
||||
- class: [`Rector\Php83\Rector\ClassConst\AddTypeToConstRector`](../rules/Php83/Rector/ClassConst/AddTypeToConstRector.php)
|
||||
|
||||
|
@ -5304,6 +5471,21 @@ Combine separated host and port on `ldap_connect()` args
|
|||
|
||||
<br>
|
||||
|
||||
## Php84
|
||||
|
||||
### ExplicitNullableParamTypeRector
|
||||
|
||||
Make implicit nullable param to explicit
|
||||
|
||||
- class: [`Rector\Php84\Rector\Param\ExplicitNullableParamTypeRector`](../rules/Php84/Rector/Param/ExplicitNullableParamTypeRector.php)
|
||||
|
||||
```diff
|
||||
-function foo(string $param = null) {}
|
||||
+function foo(?string $param = null) {}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## Privatization
|
||||
|
||||
### FinalizeClassesWithoutChildrenRector
|
||||
|
@ -5332,10 +5514,10 @@ PHPUnit test case will be finalized
|
|||
- class: [`Rector\Privatization\Rector\Class_\FinalizeTestCaseClassRector`](../rules/Privatization/Rector/Class_/FinalizeTestCaseClassRector.php)
|
||||
|
||||
```diff
|
||||
-use PHPUnit\Framework\TestCase;
|
||||
+final use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SomeClass extends TestCase
|
||||
-class SomeClass extends TestCase
|
||||
+final class SomeClass extends TestCase
|
||||
{
|
||||
}
|
||||
```
|
||||
|
@ -5577,6 +5759,21 @@ Replace constant by new ones
|
|||
|
||||
<br>
|
||||
|
||||
### RenameFunctionLikeParamWithinCallLikeArgRector
|
||||
|
||||
Rename param within closures and arrow functions based on use with specified method calls
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\Renaming\Rector\FunctionLike\RenameFunctionLikeParamWithinCallLikeArgRector`](../rules/Renaming/Rector/FunctionLike/RenameFunctionLikeParamWithinCallLikeArgRector.php)
|
||||
|
||||
```diff
|
||||
-(new SomeClass)->process(function ($param) {});
|
||||
+(new SomeClass)->process(function ($parameter) {});
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### RenameFunctionRector
|
||||
|
||||
Turns defined function call new one.
|
||||
|
@ -5813,6 +6010,21 @@ Add interface by used trait
|
|||
|
||||
<br>
|
||||
|
||||
### ArrayDimFetchToMethodCallRector
|
||||
|
||||
Change array dim fetch to method call
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\Transform\Rector\ArrayDimFetch\ArrayDimFetchToMethodCallRector`](../rules/Transform/Rector/ArrayDimFetch/ArrayDimFetchToMethodCallRector.php)
|
||||
|
||||
```diff
|
||||
-$app['someService'];
|
||||
+$app->make('someService');
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### AttributeKeyToClassConstFetchRector
|
||||
|
||||
Replace key value on specific attribute to class constant
|
||||
|
@ -5835,6 +6047,21 @@ Replace key value on specific attribute to class constant
|
|||
|
||||
<br>
|
||||
|
||||
### ConstFetchToClassConstFetchRector
|
||||
|
||||
Change const fetch to class const fetch
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\Transform\Rector\ConstFetch\ConstFetchToClassConstFetchRector`](../rules/Transform/Rector/ConstFetch/ConstFetchToClassConstFetchRector.php)
|
||||
|
||||
```diff
|
||||
-$x = CONTEXT_COURSE
|
||||
+$x = course::LEVEL
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### FuncCallToConstFetchRector
|
||||
|
||||
Changes use of function calls to use constants
|
||||
|
@ -6085,6 +6312,21 @@ Replaces properties assign calls be defined methods.
|
|||
|
||||
<br>
|
||||
|
||||
### RectorConfigBuilderRector
|
||||
|
||||
Change RectorConfig to RectorConfigBuilder
|
||||
|
||||
- class: [`Rector\Transform\Rector\FileWithoutNamespace\RectorConfigBuilderRector`](../rules/Transform/Rector/FileWithoutNamespace/RectorConfigBuilderRector.php)
|
||||
|
||||
```diff
|
||||
-return static function (RectorConfig $rectorConfig): void {
|
||||
- $rectorConfig->rule(SomeRector::class);
|
||||
-};
|
||||
+return RectorConfig::configure()->rules([SomeRector::class]);
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### ReplaceParentCallByPropertyCallRector
|
||||
|
||||
Changes method calls in child of specific types to defined property method call
|
||||
|
@ -6253,6 +6495,34 @@ Add known return type to arrow function
|
|||
|
||||
<br>
|
||||
|
||||
### AddClosureVoidReturnTypeWhereNoReturnRector
|
||||
|
||||
Add closure return type void if there is no return
|
||||
|
||||
- class: [`Rector\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector`](../rules/TypeDeclaration/Rector/Closure/AddClosureVoidReturnTypeWhereNoReturnRector.php)
|
||||
|
||||
```diff
|
||||
-function () {
|
||||
+function (): void {
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### AddFunctionVoidReturnTypeWhereNoReturnRector
|
||||
|
||||
Add function return type void if there is no return
|
||||
|
||||
- class: [`Rector\TypeDeclaration\Rector\Function_\AddFunctionVoidReturnTypeWhereNoReturnRector`](../rules/TypeDeclaration/Rector/Function_/AddFunctionVoidReturnTypeWhereNoReturnRector.php)
|
||||
|
||||
```diff
|
||||
-function restore() {
|
||||
+function restore(): void {
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### AddMethodCallBasedStrictParamTypeRector
|
||||
|
||||
Change private method param type to strict type, based on passed strict types
|
||||
|
@ -6324,6 +6594,21 @@ Add param types where needed
|
|||
|
||||
<br>
|
||||
|
||||
### AddParamTypeForFunctionLikeWithinCallLikeArgDeclarationRector
|
||||
|
||||
Add param types where needed
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\TypeDeclaration\Rector\FunctionLike\AddParamTypeForFunctionLikeWithinCallLikeArgDeclarationRector`](../rules/TypeDeclaration/Rector/FunctionLike/AddParamTypeForFunctionLikeWithinCallLikeArgDeclarationRector.php)
|
||||
|
||||
```diff
|
||||
-(new SomeClass)->process(function ($parameter) {});
|
||||
+(new SomeClass)->process(function (string $parameter) {});
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### AddParamTypeFromPropertyTypeRector
|
||||
|
||||
Adds param type declaration based on property type the value is assigned to PHPUnit provider return type declaration
|
||||
|
@ -6452,6 +6737,26 @@ Changes defined return typehint of method and class.
|
|||
|
||||
<br>
|
||||
|
||||
### AddTestsVoidReturnTypeWhereNoReturnRector
|
||||
|
||||
Add void to PHPUnit test methods
|
||||
|
||||
- class: [`Rector\TypeDeclaration\Rector\Class_\AddTestsVoidReturnTypeWhereNoReturnRector`](../rules/TypeDeclaration/Rector/Class_/AddTestsVoidReturnTypeWhereNoReturnRector.php)
|
||||
|
||||
```diff
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SomeClass extends TestCase
|
||||
{
|
||||
- public function testSomething()
|
||||
+ public function testSomething(): void
|
||||
{
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### AddVoidReturnTypeWhereNoReturnRector
|
||||
|
||||
Add return type void to function like without any return
|
||||
|
@ -6515,6 +6820,32 @@ Change return type based on strict returns type operations
|
|||
|
||||
<br>
|
||||
|
||||
### ChildDoctrineRepositoryClassTypeRector
|
||||
|
||||
Add return type to classes that extend `Doctrine\ORM\EntityRepository` based on return Doctrine method names
|
||||
|
||||
- class: [`Rector\TypeDeclaration\Rector\Class_\ChildDoctrineRepositoryClassTypeRector`](../rules/TypeDeclaration/Rector/Class_/ChildDoctrineRepositoryClassTypeRector.php)
|
||||
|
||||
```diff
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
/**
|
||||
* @extends EntityRepository<SomeType>
|
||||
*/
|
||||
final class SomeRepository extends EntityRepository
|
||||
{
|
||||
- public function getActiveItem()
|
||||
+ public function getActiveItem(): ?SomeType
|
||||
{
|
||||
return $this->findOneBy([
|
||||
'something'
|
||||
]);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### DeclareStrictTypesRector
|
||||
|
||||
Add declare(strict_types=1) if missing
|
||||
|
@ -6554,6 +6885,24 @@ Change `empty()` on nullable object to instanceof check
|
|||
|
||||
<br>
|
||||
|
||||
### IncreaseDeclareStrictTypesRector
|
||||
|
||||
Add declare strict types to a limited amount of classes at a time, to try out in the wild and increase level gradually
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\TypeDeclaration\Rector\StmtsAwareInterface\IncreaseDeclareStrictTypesRector`](../rules/TypeDeclaration/Rector/StmtsAwareInterface/IncreaseDeclareStrictTypesRector.php)
|
||||
|
||||
```diff
|
||||
+declare(strict_types=1);
|
||||
+
|
||||
function someFunction()
|
||||
{
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### MergeDateTimePropertyTypeDeclarationRector
|
||||
|
||||
Set DateTime to DateTimeInterface for DateTime property with DateTimeInterface docblock
|
||||
|
|
|
@ -291,6 +291,9 @@ require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/InvalidTagV
|
|||
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/MethodTagValueNode.php';
|
||||
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/MethodTagValueParameterNode.php';
|
||||
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/MixinTagValueNode.php';
|
||||
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/ParamClosureThisTagValueNode.php';
|
||||
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/ParamImmediatelyInvokedCallableTagValueNode.php';
|
||||
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/ParamLaterInvokedCallableTagValueNode.php';
|
||||
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/ParamOutTagValueNode.php';
|
||||
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/ParamTagValueNode.php';
|
||||
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/PhpDocChildNode.php';
|
||||
|
|
|
@ -29,7 +29,7 @@ use Rector\Rector\AbstractRector;
|
|||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix202402\Webmozart\Assert\Assert;
|
||||
use RectorPrefix202405\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @see \Rector\Tests\Arguments\Rector\ClassMethod\ArgumentAdderRector\ArgumentAdderRectorTest
|
||||
*/
|
||||
|
|
|
@ -15,7 +15,7 @@ use Rector\Rector\AbstractRector;
|
|||
use Rector\ValueObject\MethodName;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix202402\Webmozart\Assert\Assert;
|
||||
use RectorPrefix202405\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @api used in rector-symfony
|
||||
* @see \Rector\Tests\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector\ReplaceArgumentDefaultValueRectorTest
|
||||
|
|
|
@ -11,7 +11,7 @@ use Rector\Contract\Rector\ConfigurableRectorInterface;
|
|||
use Rector\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix202402\Webmozart\Assert\Assert;
|
||||
use RectorPrefix202405\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @changelog https://php.watch/versions/8.1/version_compare-operator-restrictions
|
||||
* @changelog https://github.com/rectorphp/rector/issues/6271
|
||||
|
|
|
@ -11,7 +11,7 @@ use Rector\Contract\Rector\ConfigurableRectorInterface;
|
|||
use Rector\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix202402\Webmozart\Assert\Assert;
|
||||
use RectorPrefix202405\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @see \Rector\Tests\Arguments\Rector\MethodCall\RemoveMethodCallParamRector\RemoveMethodCallParamRectorTest
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Carbon\NodeFactory;
|
||||
|
||||
use RectorPrefix202405\Nette\Utils\Strings;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
final class CarbonCallFactory
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* @see https://regex101.com/r/9vGt8r/1
|
||||
*/
|
||||
private const DAY_COUNT_REGEX = '#\\+(\\s+)?(?<count>\\d+)(\\s+)?(day|days)#';
|
||||
/**
|
||||
* @var string
|
||||
* @see https://regex101.com/r/6VUUQF/1
|
||||
*/
|
||||
private const MONTH_COUNT_REGEX = '#\\+(\\s+)?(?<count>\\d+)(\\s+)?(month|months)#';
|
||||
/**
|
||||
* @var array<self::*_REGEX, string>
|
||||
*/
|
||||
private const REGEX_TO_METHOD_NAME_MAP = [self::DAY_COUNT_REGEX => 'addDays', self::MONTH_COUNT_REGEX => 'addMonths'];
|
||||
/**
|
||||
* @return \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall
|
||||
*/
|
||||
public function createFromDateTimeString(FullyQualified $carbonFullyQualified, String_ $string)
|
||||
{
|
||||
$dateTimeValue = $string->value;
|
||||
if ($dateTimeValue === 'now') {
|
||||
return new StaticCall($carbonFullyQualified, new Identifier('now'));
|
||||
}
|
||||
if ($dateTimeValue === 'today') {
|
||||
return new StaticCall($carbonFullyQualified, new Identifier('today'));
|
||||
}
|
||||
$hasToday = Strings::match($dateTimeValue, '#today#');
|
||||
if ($hasToday !== null) {
|
||||
$carbonCall = new StaticCall($carbonFullyQualified, new Identifier('today'));
|
||||
} else {
|
||||
$carbonCall = new StaticCall($carbonFullyQualified, new Identifier('now'));
|
||||
}
|
||||
foreach (self::REGEX_TO_METHOD_NAME_MAP as $regex => $methodName) {
|
||||
$match = Strings::match($dateTimeValue, $regex);
|
||||
if ($match === null) {
|
||||
continue;
|
||||
}
|
||||
$countLNumber = new LNumber((int) $match['count']);
|
||||
$carbonCall = new MethodCall($carbonCall, new Identifier($methodName), [new Arg($countLNumber)]);
|
||||
}
|
||||
return $carbonCall;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Carbon\Rector\FuncCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector\DateFuncCallToCarbonRectorTest
|
||||
*/
|
||||
final class DateFuncCallToCarbonRector extends AbstractRector
|
||||
{
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Convert date() function call to Carbon::*()', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$date = date('Y-m-d');
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$date = \Carbon\Carbon::now()->format('Y-m-d')
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [FuncCall::class];
|
||||
}
|
||||
/**
|
||||
* @param FuncCall $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if (!$this->isName($node->name, 'date')) {
|
||||
return null;
|
||||
}
|
||||
if ($node->isFirstClassCallable()) {
|
||||
return null;
|
||||
}
|
||||
if (\count($node->getArgs()) !== 1) {
|
||||
return null;
|
||||
}
|
||||
$firstArg = $node->getArgs()[0];
|
||||
if (!$firstArg->value instanceof String_) {
|
||||
return null;
|
||||
}
|
||||
// create now and format()
|
||||
$nowStaticCall = new StaticCall(new FullyQualified('Carbon\\Carbon'), 'now');
|
||||
return new MethodCall($nowStaticCall, 'format', [new Arg($firstArg->value)]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Carbon\Rector\MethodCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use Rector\Carbon\NodeFactory\CarbonCallFactory;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\Carbon\Rector\MethodCall\DateTimeMethodCallToCarbonRector\DateTimeMethodCallToCarbonRectorTest
|
||||
*/
|
||||
final class DateTimeMethodCallToCarbonRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Carbon\NodeFactory\CarbonCallFactory
|
||||
*/
|
||||
private $carbonCallFactory;
|
||||
public function __construct(CarbonCallFactory $carbonCallFactory)
|
||||
{
|
||||
$this->carbonCallFactory = $carbonCallFactory;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Convert new DateTime() with a method call to Carbon::*()', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$date = (new \DateTime('today +20 day'))->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$date = \Carbon\Carbon::today()->addDays(20)->format('Y-m-d')
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [MethodCall::class];
|
||||
}
|
||||
/**
|
||||
* @param MethodCall $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if (!$node->var instanceof New_) {
|
||||
return null;
|
||||
}
|
||||
$new = $node->var;
|
||||
if (!$new->class instanceof Name) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isName($new->class, 'DateTime')) {
|
||||
return null;
|
||||
}
|
||||
if ($new->isFirstClassCallable()) {
|
||||
return null;
|
||||
}
|
||||
if (\count($new->getArgs()) !== 1) {
|
||||
// @todo handle in separate static call
|
||||
return null;
|
||||
}
|
||||
$firstArg = $new->getArgs()[0];
|
||||
if (!$firstArg->value instanceof String_) {
|
||||
return null;
|
||||
}
|
||||
$carbonFullyQualified = new FullyQualified('Carbon\\Carbon');
|
||||
$carbonCall = $this->carbonCallFactory->createFromDateTimeString($carbonFullyQualified, $firstArg->value);
|
||||
$node->var = $carbonCall;
|
||||
return $node;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Carbon\Rector\New_;
|
||||
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use Rector\Carbon\NodeFactory\CarbonCallFactory;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @changelog https://github.com/briannesbitt/Carbon/issues/231
|
||||
*
|
||||
* @see \Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\DateTimeInstanceToCarbonRectorTest
|
||||
*/
|
||||
final class DateTimeInstanceToCarbonRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Carbon\NodeFactory\CarbonCallFactory
|
||||
*/
|
||||
private $carbonCallFactory;
|
||||
public function __construct(CarbonCallFactory $carbonCallFactory)
|
||||
{
|
||||
$this->carbonCallFactory = $carbonCallFactory;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Convert new DateTime() to Carbon::*()', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
$date = new \DateTime('today');
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
$date = \Carbon\Carbon::today();
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [New_::class];
|
||||
}
|
||||
/**
|
||||
* @param New_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if ($this->isName($node->class, 'DateTime')) {
|
||||
return $this->refactorWithClass($node, 'Carbon\\Carbon');
|
||||
}
|
||||
if ($this->isName($node->class, 'DateTimeImmutable')) {
|
||||
return $this->refactorWithClass($node, 'Carbon\\CarbonImmutable');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @return \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|null
|
||||
*/
|
||||
public function refactorWithClass(New_ $new, string $className)
|
||||
{
|
||||
if ($new->isFirstClassCallable()) {
|
||||
return null;
|
||||
}
|
||||
// no arg? ::now()
|
||||
$carbonFullyQualified = new FullyQualified($className);
|
||||
if ($new->args === []) {
|
||||
return new StaticCall($carbonFullyQualified, new Identifier('now'));
|
||||
}
|
||||
if (\count($new->getArgs()) === 1) {
|
||||
$firstArg = $new->getArgs()[0];
|
||||
if ($firstArg->value instanceof String_) {
|
||||
return $this->carbonCallFactory->createFromDateTimeString($carbonFullyQualified, $firstArg->value);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -47,6 +47,9 @@ final class VariableDimFetchAssignResolver
|
|||
}
|
||||
$assign = $stmtExpr;
|
||||
$keyExpr = $this->matchKeyOnArrayDimFetchOfVariable($assign, $variable);
|
||||
if ($assign->var instanceof ArrayDimFetch && $assign->var->var instanceof ArrayDimFetch) {
|
||||
return [];
|
||||
}
|
||||
$keysAndExprs[] = new KeyAndExpr($keyExpr, $assign->expr, $stmt->getComments());
|
||||
}
|
||||
// we can only work with same variable
|
||||
|
|
|
@ -5,6 +5,9 @@ namespace Rector\CodeQuality\Rector\Array_;
|
|||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Stmt\ClassConst;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\Php\PhpMethodReflection;
|
||||
use Rector\NodeCollector\NodeAnalyzer\ArrayCallableMethodMatcher;
|
||||
|
@ -89,13 +92,17 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Array_::class];
|
||||
return [Property::class, ClassConst::class, Array_::class];
|
||||
}
|
||||
/**
|
||||
* @param Array_ $node
|
||||
* @param Property|ClassConst|Array_ $node
|
||||
* @return null|int|\PhpParser\Node
|
||||
*/
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope)
|
||||
{
|
||||
if ($node instanceof Property || $node instanceof ClassConst) {
|
||||
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
|
||||
}
|
||||
if ($this->shouldSkipTwigExtension($scope)) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,174 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\CodeQuality\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\UnionType;
|
||||
use PHPStan\Type\VoidType;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
|
||||
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
|
||||
use Rector\TypeDeclaration\TypeInferer\SilentVoidResolver;
|
||||
use Rector\ValueObject\MethodName;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\ExplicitReturnNullRectorTest
|
||||
*/
|
||||
final class ExplicitReturnNullRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\TypeDeclaration\TypeInferer\SilentVoidResolver
|
||||
*/
|
||||
private $silentVoidResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
|
||||
*/
|
||||
private $phpDocInfoFactory;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeTypeResolver\PHPStan\Type\TypeFactory
|
||||
*/
|
||||
private $typeFactory;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger
|
||||
*/
|
||||
private $phpDocTypeChanger;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer
|
||||
*/
|
||||
private $returnTypeInferer;
|
||||
public function __construct(SilentVoidResolver $silentVoidResolver, PhpDocInfoFactory $phpDocInfoFactory, TypeFactory $typeFactory, PhpDocTypeChanger $phpDocTypeChanger, ReturnTypeInferer $returnTypeInferer)
|
||||
{
|
||||
$this->silentVoidResolver = $silentVoidResolver;
|
||||
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
||||
$this->typeFactory = $typeFactory;
|
||||
$this->phpDocTypeChanger = $phpDocTypeChanger;
|
||||
$this->returnTypeInferer = $returnTypeInferer;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Add explicit return null to method/function that returns a value, but missed main return', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @return string|void
|
||||
*/
|
||||
public function run(int $number)
|
||||
{
|
||||
if ($number > 50) {
|
||||
return 'yes';
|
||||
}
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function run(int $number)
|
||||
{
|
||||
if ($number > 50) {
|
||||
return 'yes';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [ClassMethod::class, Function_::class];
|
||||
}
|
||||
/**
|
||||
* @param ClassMethod|Function_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
// known return type, nothing to improve
|
||||
if ($node->returnType instanceof Node) {
|
||||
return null;
|
||||
}
|
||||
if ($node instanceof ClassMethod && $this->isName($node, MethodName::CONSTRUCT)) {
|
||||
return null;
|
||||
}
|
||||
$returnType = $this->returnTypeInferer->inferFunctionLike($node);
|
||||
if (!$returnType instanceof UnionType) {
|
||||
return null;
|
||||
}
|
||||
$hasChanged = \false;
|
||||
$this->traverseNodesWithCallable((array) $node->stmts, static function (Node $node) use(&$hasChanged) {
|
||||
if ($node instanceof Class_ || $node instanceof Function_ || $node instanceof Closure) {
|
||||
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
|
||||
}
|
||||
if ($node instanceof Return_ && !$node->expr instanceof Expr) {
|
||||
$hasChanged = \true;
|
||||
$node->expr = new ConstFetch(new Name('null'));
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
if (!$this->silentVoidResolver->hasSilentVoid($node)) {
|
||||
if ($hasChanged) {
|
||||
$this->transformDocUnionVoidToUnionNull($node);
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
$node->stmts[] = new Return_(new ConstFetch(new Name('null')));
|
||||
$this->transformDocUnionVoidToUnionNull($node);
|
||||
return $node;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $node
|
||||
*/
|
||||
private function transformDocUnionVoidToUnionNull($node) : void
|
||||
{
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
|
||||
$returnType = $phpDocInfo->getReturnType();
|
||||
if (!$returnType instanceof UnionType) {
|
||||
return;
|
||||
}
|
||||
$newTypes = [];
|
||||
$hasChanged = \false;
|
||||
foreach ($returnType->getTypes() as $type) {
|
||||
if ($type instanceof VoidType) {
|
||||
$type = new NullType();
|
||||
$hasChanged = \true;
|
||||
}
|
||||
$newTypes[] = $type;
|
||||
}
|
||||
if (!$hasChanged) {
|
||||
return;
|
||||
}
|
||||
$type = $this->typeFactory->createMixedPassedOrUnionTypeAndKeepConstant($newTypes);
|
||||
if (!$type instanceof UnionType) {
|
||||
return;
|
||||
}
|
||||
$this->phpDocTypeChanger->changeReturnType($node, $phpDocInfo, $type);
|
||||
}
|
||||
}
|
|
@ -152,6 +152,7 @@ CODE_SAMPLE
|
|||
{
|
||||
\end($stmts);
|
||||
$lastKey = \key($stmts);
|
||||
\reset($stmts);
|
||||
foreach ($stmts as $key => $stmt) {
|
||||
if ($key === $lastKey) {
|
||||
// skip last item
|
||||
|
|
|
@ -121,7 +121,7 @@ CODE_SAMPLE
|
|||
if (!$node instanceof StaticCall) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isName($node->class, 'self')) {
|
||||
if (!$this->isNames($node->class, ['self', 'static'])) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isName($node->name, $classMethodName)) {
|
||||
|
@ -151,7 +151,7 @@ CODE_SAMPLE
|
|||
if (!$node instanceof StaticCall) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isName($node->class, 'self')) {
|
||||
if (!$this->isNames($node->class, ['self', 'static'])) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isName($node->name, $currentClassMethodName)) {
|
||||
|
|
|
@ -4,12 +4,16 @@ declare (strict_types=1);
|
|||
namespace Rector\CodeQuality\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\FunctionReflection;
|
||||
use PHPStan\Reflection\MethodReflection;
|
||||
use PHPStan\Reflection\Native\NativeFunctionReflection;
|
||||
use Rector\CodingStyle\Reflection\VendorLocationDetector;
|
||||
use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper;
|
||||
use Rector\Php80\NodeResolver\ArgumentSorter;
|
||||
|
@ -81,41 +85,49 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [ClassMethod::class, New_::class, MethodCall::class, StaticCall::class];
|
||||
return [ClassMethod::class, Function_::class, New_::class, MethodCall::class, StaticCall::class, FuncCall::class];
|
||||
}
|
||||
/**
|
||||
* @param ClassMethod|New_|MethodCall|StaticCall $node
|
||||
* @return \PhpParser\Node\Stmt\ClassMethod|null|\PhpParser\Node\Expr\New_|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall
|
||||
* @param ClassMethod|Function_|New_|MethodCall|StaticCall|FuncCall $node
|
||||
* @return \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|null|\PhpParser\Node\Expr\New_|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\FuncCall
|
||||
*/
|
||||
public function refactorWithScope(Node $node, Scope $scope)
|
||||
{
|
||||
if ($node instanceof ClassMethod) {
|
||||
return $this->refactorClassMethod($node, $scope);
|
||||
if ($node instanceof ClassMethod || $node instanceof Function_) {
|
||||
return $this->refactorClassMethodOrFunction($node, $scope);
|
||||
}
|
||||
if ($node instanceof New_) {
|
||||
return $this->refactorNew($node, $scope);
|
||||
}
|
||||
return $this->refactorMethodCall($node, $scope);
|
||||
return $this->refactorMethodCallOrFuncCall($node, $scope);
|
||||
}
|
||||
private function refactorClassMethod(ClassMethod $classMethod, Scope $scope) : ?ClassMethod
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $node
|
||||
* @return \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|null
|
||||
*/
|
||||
private function refactorClassMethodOrFunction($node, Scope $scope)
|
||||
{
|
||||
if ($classMethod->params === []) {
|
||||
if ($node->params === []) {
|
||||
return null;
|
||||
}
|
||||
if ($classMethod->getAttribute(self::HAS_SWAPPED_PARAMS, \false) === \true) {
|
||||
if ($node->getAttribute(self::HAS_SWAPPED_PARAMS, \false) === \true) {
|
||||
return null;
|
||||
}
|
||||
$classMethodReflection = $this->reflectionResolver->resolveMethodReflectionFromClassMethod($classMethod, $scope);
|
||||
if (!$classMethodReflection instanceof MethodReflection) {
|
||||
if ($node instanceof ClassMethod) {
|
||||
$reflection = $this->reflectionResolver->resolveMethodReflectionFromClassMethod($node, $scope);
|
||||
} else {
|
||||
$reflection = $this->reflectionResolver->resolveFunctionReflectionFromFunction($node, $scope);
|
||||
}
|
||||
if (!$reflection instanceof MethodReflection && !$reflection instanceof FunctionReflection) {
|
||||
return null;
|
||||
}
|
||||
$expectedArgOrParamOrder = $this->resolveExpectedArgParamOrderIfDifferent($classMethodReflection, $classMethod, $scope);
|
||||
$expectedArgOrParamOrder = $this->resolveExpectedArgParamOrderIfDifferent($reflection, $node, $scope);
|
||||
if ($expectedArgOrParamOrder === null) {
|
||||
return null;
|
||||
}
|
||||
$classMethod->params = $this->argumentSorter->sortArgsByExpectedParamOrder($classMethod->params, $expectedArgOrParamOrder);
|
||||
$classMethod->setAttribute(self::HAS_SWAPPED_PARAMS, \true);
|
||||
return $classMethod;
|
||||
$node->params = $this->argumentSorter->sortArgsByExpectedParamOrder($node->params, $expectedArgOrParamOrder);
|
||||
$node->setAttribute(self::HAS_SWAPPED_PARAMS, \true);
|
||||
return $node;
|
||||
}
|
||||
private function refactorNew(New_ $new, Scope $scope) : ?New_
|
||||
{
|
||||
|
@ -137,39 +149,46 @@ CODE_SAMPLE
|
|||
return $new;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $methodCall
|
||||
* @return \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|null
|
||||
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\FuncCall $node
|
||||
* @return \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\FuncCall|null
|
||||
*/
|
||||
private function refactorMethodCall($methodCall, Scope $scope)
|
||||
private function refactorMethodCallOrFuncCall($node, Scope $scope)
|
||||
{
|
||||
if ($methodCall->isFirstClassCallable()) {
|
||||
if ($node->isFirstClassCallable()) {
|
||||
return null;
|
||||
}
|
||||
$methodReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($methodCall);
|
||||
if (!$methodReflection instanceof MethodReflection) {
|
||||
$reflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($node);
|
||||
if (!$reflection instanceof MethodReflection && !$reflection instanceof FunctionReflection) {
|
||||
return null;
|
||||
}
|
||||
$expectedArgOrParamOrder = $this->resolveExpectedArgParamOrderIfDifferent($methodReflection, $methodCall, $scope);
|
||||
$expectedArgOrParamOrder = $this->resolveExpectedArgParamOrderIfDifferent($reflection, $node, $scope);
|
||||
if ($expectedArgOrParamOrder === null) {
|
||||
return null;
|
||||
}
|
||||
$newArgs = $this->argumentSorter->sortArgsByExpectedParamOrder($methodCall->getArgs(), $expectedArgOrParamOrder);
|
||||
if ($methodCall->args === $newArgs) {
|
||||
$newArgs = $this->argumentSorter->sortArgsByExpectedParamOrder($node->getArgs(), $expectedArgOrParamOrder);
|
||||
if ($node->args === $newArgs) {
|
||||
return null;
|
||||
}
|
||||
$methodCall->args = $newArgs;
|
||||
return $methodCall;
|
||||
$node->args = $newArgs;
|
||||
return $node;
|
||||
}
|
||||
/**
|
||||
* @return int[]|null
|
||||
* @param \PhpParser\Node\Expr\New_|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Expr\StaticCall $node
|
||||
* @param \PHPStan\Reflection\MethodReflection|\PHPStan\Reflection\FunctionReflection $reflection
|
||||
* @param \PhpParser\Node\Expr\New_|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\FuncCall $node
|
||||
*/
|
||||
private function resolveExpectedArgParamOrderIfDifferent(MethodReflection $methodReflection, $node, Scope $scope) : ?array
|
||||
private function resolveExpectedArgParamOrderIfDifferent($reflection, $node, Scope $scope) : ?array
|
||||
{
|
||||
if ($this->vendorLocationDetector->detectMethodReflection($methodReflection)) {
|
||||
if ($reflection instanceof NativeFunctionReflection) {
|
||||
return null;
|
||||
}
|
||||
$parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select($methodReflection, $node, $scope);
|
||||
if ($reflection instanceof MethodReflection && $this->vendorLocationDetector->detectMethodReflection($reflection)) {
|
||||
return null;
|
||||
}
|
||||
if ($reflection instanceof FunctionReflection && $this->vendorLocationDetector->detectFunctionReflection($reflection)) {
|
||||
return null;
|
||||
}
|
||||
$parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select($reflection, $node, $scope);
|
||||
$expectedParameterReflections = $this->requireOptionalParamResolver->resolveFromParametersAcceptor($parametersAcceptor);
|
||||
if ($expectedParameterReflections === $parametersAcceptor->getParameters()) {
|
||||
return null;
|
||||
|
|
|
@ -4,6 +4,7 @@ declare (strict_types=1);
|
|||
namespace Rector\CodeQuality\Rector\Class_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
|
@ -154,7 +155,10 @@ CODE_SAMPLE
|
|||
if ($classReflection->hasMethod('__set')) {
|
||||
return \true;
|
||||
}
|
||||
return $classReflection->hasMethod('__get');
|
||||
if ($classReflection->hasMethod('__get')) {
|
||||
return \true;
|
||||
}
|
||||
return $class->extends instanceof FullyQualified && !$this->reflectionProvider->hasClass($class->extends->toString());
|
||||
}
|
||||
/**
|
||||
* @param array<string, Type> $fetchedLocalPropertyNameToTypes
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\CodeQuality\Rector\Class_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Rector\Enum\ObjectReference;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @changelog https://3v4l.org/JK1g2#v5.0.0
|
||||
* @see \Rector\Tests\CodeQuality\Rector\Class_\StaticToSelfStaticMethodCallOnFinalClassRector\StaticToSelfStaticMethodCallOnFinalClassRectorTest
|
||||
*/
|
||||
final class StaticToSelfStaticMethodCallOnFinalClassRector extends AbstractRector
|
||||
{
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Change `static::methodCall()` to `self::methodCall()` on final class', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
public function d()
|
||||
{
|
||||
echo static::run();
|
||||
}
|
||||
|
||||
private static function run()
|
||||
{
|
||||
echo 'test';
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
public function d()
|
||||
{
|
||||
echo self::run();
|
||||
}
|
||||
|
||||
private static function run()
|
||||
{
|
||||
echo 'test';
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Class_::class];
|
||||
}
|
||||
/**
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Class_
|
||||
{
|
||||
if (!$node->isFinal()) {
|
||||
return null;
|
||||
}
|
||||
$hasChanged = \false;
|
||||
$this->traverseNodesWithCallable($node->stmts, function (Node $subNode) use(&$hasChanged, $node) : ?StaticCall {
|
||||
if (!$subNode instanceof StaticCall) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isName($subNode->class, ObjectReference::STATIC)) {
|
||||
return null;
|
||||
}
|
||||
// skip dynamic method
|
||||
if (!$subNode->name instanceof Identifier) {
|
||||
return null;
|
||||
}
|
||||
$methodName = (string) $this->getName($subNode->name);
|
||||
$targetClassMethod = $node->getMethod($methodName);
|
||||
// skip call non-existing method from current class to ensure transformation is safe
|
||||
if (!$targetClassMethod instanceof ClassMethod) {
|
||||
return null;
|
||||
}
|
||||
// avoid overlapped change
|
||||
if (!$targetClassMethod->isStatic()) {
|
||||
return null;
|
||||
}
|
||||
$hasChanged = \true;
|
||||
$subNode->class = new Name('self');
|
||||
return $subNode;
|
||||
});
|
||||
if ($hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\CodeQuality\Rector\Concat;
|
||||
|
||||
use RectorPrefix202402\Nette\Utils\Strings;
|
||||
use RectorPrefix202405\Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\BinaryOp\Concat;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
|
|
|
@ -55,21 +55,29 @@ CODE_SAMPLE
|
|||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
$leftStaticType = $this->nodeTypeResolver->getNativeType($node->left);
|
||||
// objects can be different by content
|
||||
if ($leftStaticType instanceof ObjectType) {
|
||||
return null;
|
||||
}
|
||||
if ($leftStaticType instanceof MixedType) {
|
||||
return null;
|
||||
}
|
||||
$rightStaticType = $this->nodeTypeResolver->getNativeType($node->right);
|
||||
if ($rightStaticType instanceof MixedType) {
|
||||
// objects can be different by content
|
||||
if ($leftStaticType instanceof ObjectType || $rightStaticType instanceof ObjectType) {
|
||||
return null;
|
||||
}
|
||||
if ($leftStaticType instanceof MixedType || $rightStaticType instanceof MixedType) {
|
||||
return null;
|
||||
}
|
||||
if ($leftStaticType->isString()->yes() && $rightStaticType->isString()->yes()) {
|
||||
return $this->processIdenticalOrNotIdentical($node);
|
||||
}
|
||||
// different types
|
||||
if (!$leftStaticType->equals($rightStaticType)) {
|
||||
return null;
|
||||
}
|
||||
return $this->processIdenticalOrNotIdentical($node);
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\BinaryOp\Equal|\PhpParser\Node\Expr\BinaryOp\NotEqual $node
|
||||
* @return \PhpParser\Node\Expr\BinaryOp\Identical|\PhpParser\Node\Expr\BinaryOp\NotIdentical
|
||||
*/
|
||||
private function processIdenticalOrNotIdentical($node)
|
||||
{
|
||||
if ($node instanceof Equal) {
|
||||
return new Identical($node->left, $node->right);
|
||||
}
|
||||
|
|
|
@ -6,10 +6,11 @@ namespace Rector\CodeQuality\Rector\Expression;
|
|||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Ternary;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use Rector\DeadCode\SideEffect\SideEffectNodeDetector;
|
||||
use Rector\NodeAnalyzer\ExprAnalyzer;
|
||||
use Rector\Rector\AbstractScopeAwareRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
@ -20,12 +21,12 @@ final class TernaryFalseExpressionToIfRector extends AbstractScopeAwareRector
|
|||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\DeadCode\SideEffect\SideEffectNodeDetector
|
||||
* @var \Rector\NodeAnalyzer\ExprAnalyzer
|
||||
*/
|
||||
private $sideEffectNodeDetector;
|
||||
public function __construct(SideEffectNodeDetector $sideEffectNodeDetector)
|
||||
private $exprAnalyzer;
|
||||
public function __construct(ExprAnalyzer $exprAnalyzer)
|
||||
{
|
||||
$this->sideEffectNodeDetector = $sideEffectNodeDetector;
|
||||
$this->exprAnalyzer = $exprAnalyzer;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
|
@ -70,7 +71,7 @@ CODE_SAMPLE
|
|||
if (!$ternary->if instanceof Expr) {
|
||||
return null;
|
||||
}
|
||||
if ($this->sideEffectNodeDetector->detect($ternary->else, $scope) || $this->sideEffectNodeDetector->detectCallExpr($ternary->else, $scope)) {
|
||||
if (!$ternary->else instanceof Variable && $this->exprAnalyzer->isDynamicExpr($ternary->else)) {
|
||||
return null;
|
||||
}
|
||||
return new If_($ternary->cond, ['stmts' => [new Expression($ternary->if)]]);
|
||||
|
|
|
@ -13,13 +13,14 @@ use PhpParser\Node\Expr\Variable;
|
|||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\For_;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use Rector\Rector\AbstractScopeAwareRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\CodeQuality\Rector\For_\ForRepeatedCountToOwnVariableRector\ForRepeatedCountToOwnVariableRectorTest
|
||||
*/
|
||||
final class ForRepeatedCountToOwnVariableRector extends AbstractRector
|
||||
final class ForRepeatedCountToOwnVariableRector extends AbstractScopeAwareRector
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
|
@ -63,8 +64,11 @@ CODE_SAMPLE
|
|||
* @param For_ $node
|
||||
* @return Stmt[]|null
|
||||
*/
|
||||
public function refactor(Node $node) : ?array
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?array
|
||||
{
|
||||
if ($scope->hasVariableType(self::COUNTER_NAME)->yes()) {
|
||||
return null;
|
||||
}
|
||||
$countInCond = null;
|
||||
$counterVariable = new Variable(self::COUNTER_NAME);
|
||||
foreach ($node->cond as $condExpr) {
|
||||
|
|
|
@ -88,15 +88,16 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
$nextStmt = $node->stmts[$key + 1] ?? null;
|
||||
if (!$nextStmt instanceof Return_) {
|
||||
continue;
|
||||
}
|
||||
$return = $this->processForeachNodeWithReturnInside($foreach, $foreachReturnOrAssign, $nextStmt);
|
||||
if (!$return instanceof Return_) {
|
||||
continue;
|
||||
}
|
||||
$node->stmts[$key] = $return;
|
||||
// cleanup next return
|
||||
if ($nextStmt instanceof Return_) {
|
||||
unset($node->stmts[$key + 1]);
|
||||
}
|
||||
unset($node->stmts[$key + 1]);
|
||||
$hasChanged = \true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ CODE_SAMPLE
|
|||
if (!$nestedArrayItemItem instanceof ArrayItem) {
|
||||
continue;
|
||||
}
|
||||
$array->items[] = new ArrayItem($nestedArrayItemItem->value, $nestedArrayItemItem->key);
|
||||
$array->items[] = $nestedArrayItemItem->unpack ? $nestedArrayItemItem : new ArrayItem($nestedArrayItemItem->value, $nestedArrayItemItem->key);
|
||||
$isAssigned = \true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\CodeQuality\Rector\FuncCall;
|
||||
|
||||
use RectorPrefix202402\Nette\Utils\Strings;
|
||||
use RectorPrefix202405\Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use Rector\NodeNameResolver\Regex\RegexPatternDetector;
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\CodeQuality\Rector\FuncCall;
|
||||
|
||||
use RectorPrefix202405\Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
@ -14,6 +16,11 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
*/
|
||||
final class SimplifyStrposLowerRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* @see https://regex101.com/r/Jokjt8/1
|
||||
*/
|
||||
private const UPPERCASE_REGEX = '#[A-Z]#';
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Simplify strpos(strtolower(), "...") calls', [new CodeSample('strpos(strtolower($var), "...")', 'stripos($var, "...")')]);
|
||||
|
@ -36,10 +43,11 @@ final class SimplifyStrposLowerRector extends AbstractRector
|
|||
if ($node->isFirstClassCallable()) {
|
||||
return null;
|
||||
}
|
||||
if (!isset($node->getArgs()[0])) {
|
||||
$args = $node->getArgs();
|
||||
if (!isset($args[0], $args[1])) {
|
||||
return null;
|
||||
}
|
||||
$firstArg = $node->getArgs()[0];
|
||||
$firstArg = $args[0];
|
||||
if (!$firstArg->value instanceof FuncCall) {
|
||||
return null;
|
||||
}
|
||||
|
@ -48,6 +56,13 @@ final class SimplifyStrposLowerRector extends AbstractRector
|
|||
if (!$this->isName($innerFuncCall, 'strtolower')) {
|
||||
return null;
|
||||
}
|
||||
$secondArg = $args[1];
|
||||
if (!$secondArg->value instanceof String_) {
|
||||
return null;
|
||||
}
|
||||
if (Strings::match($secondArg->value->value, self::UPPERCASE_REGEX) !== null) {
|
||||
return null;
|
||||
}
|
||||
// pop 1 level up
|
||||
$node->args[0] = $innerFuncCall->getArgs()[0];
|
||||
$node->name = new Name('stripos');
|
||||
|
|
|
@ -22,6 +22,7 @@ use PhpParser\Node\Scalar\LNumber;
|
|||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\ElseIf_;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\NodeTypeResolver\TypeAnalyzer\ArrayTypeAnalyzer;
|
||||
use Rector\NodeTypeResolver\TypeAnalyzer\StringTypeAnalyzer;
|
||||
|
@ -110,8 +111,8 @@ CODE_SAMPLE
|
|||
if ($conditionNode instanceof Bool_) {
|
||||
return null;
|
||||
}
|
||||
$conditionStaticType = $this->getType($conditionNode);
|
||||
if ($conditionStaticType->isBoolean()->yes()) {
|
||||
$conditionStaticType = $this->nodeTypeResolver->getNativeType($conditionNode);
|
||||
if ($conditionStaticType instanceof MixedType || $conditionStaticType->isBoolean()->yes()) {
|
||||
return null;
|
||||
}
|
||||
$binaryOp = $this->resolveNewConditionNode($conditionNode, $isNegated);
|
||||
|
|
|
@ -5,7 +5,9 @@ namespace Rector\CodeQuality\Rector\If_;
|
|||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\BinaryOp\Equal;
|
||||
use PhpParser\Node\Expr\BinaryOp\Identical;
|
||||
use PhpParser\Node\Expr\BinaryOp\NotEqual;
|
||||
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
|
||||
use PhpParser\Node\Expr\BooleanNot;
|
||||
use PhpParser\Node\Stmt\Else_;
|
||||
|
@ -140,7 +142,7 @@ CODE_SAMPLE
|
|||
if (\strpos($condString, '!=') === \false) {
|
||||
return !$this->valueResolver->isTrueOrFalse($return->expr);
|
||||
}
|
||||
return !$if->cond instanceof NotIdentical;
|
||||
return !$if->cond instanceof NotIdentical && !$if->cond instanceof NotEqual;
|
||||
}
|
||||
private function processReturnTrue(If_ $if, Return_ $nextReturn) : Return_
|
||||
{
|
||||
|
@ -155,6 +157,10 @@ CODE_SAMPLE
|
|||
$notIdentical = new NotIdentical($if->cond->left, $if->cond->right);
|
||||
return new Return_($this->exprBoolCaster->boolCastOrNullCompareIfNeeded($notIdentical));
|
||||
}
|
||||
if ($if->cond instanceof Equal) {
|
||||
$notIdentical = new NotEqual($if->cond->left, $if->cond->right);
|
||||
return new Return_($this->exprBoolCaster->boolCastOrNullCompareIfNeeded($notIdentical));
|
||||
}
|
||||
if (!$nextReturn->expr instanceof Expr) {
|
||||
return null;
|
||||
}
|
||||
|
@ -207,6 +213,10 @@ CODE_SAMPLE
|
|||
$if->cond = new Identical($if->cond->left, $if->cond->right);
|
||||
return $this->processReturnTrue($if, $return);
|
||||
}
|
||||
if ($if->cond instanceof NotEqual && $this->valueResolver->isTrue($expr)) {
|
||||
$if->cond = new Equal($if->cond->left, $if->cond->right);
|
||||
return $this->processReturnTrue($if, $return);
|
||||
}
|
||||
return $this->processReturnFalse($if, $return);
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\CodeQuality\Rector\Include_;
|
||||
|
||||
use RectorPrefix202402\Nette\Utils\Strings;
|
||||
use RectorPrefix202405\Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\BinaryOp\Concat;
|
||||
use PhpParser\Node\Expr\Include_;
|
||||
|
|
|
@ -53,6 +53,6 @@ final class SimplifyTautologyTernaryRector extends AbstractRector
|
|||
if (!$twoNodeMatch instanceof TwoNodeMatch) {
|
||||
return null;
|
||||
}
|
||||
return $node->if;
|
||||
return $node->cond instanceof NotIdentical ? $node->if : $node->else;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\CodingStyle\Application;
|
||||
|
||||
use RectorPrefix202402\Nette\Utils\Strings;
|
||||
use RectorPrefix202405\Nette\Utils\Strings;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Declare_;
|
||||
|
|
|
@ -3,11 +3,10 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter;
|
||||
|
||||
use RectorPrefix202402\Nette\Utils\Strings;
|
||||
use RectorPrefix202405\Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use Rector\CodingStyle\ClassNameImport\ShortNameResolver;
|
||||
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
|
||||
use Rector\Configuration\RenamedClassesDataCollector;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Rector\ValueObject\Application\File;
|
||||
/**
|
||||
|
@ -26,15 +25,9 @@ final class FullyQualifiedNameClassNameImportSkipVoter implements ClassNameImpor
|
|||
* @var \Rector\CodingStyle\ClassNameImport\ShortNameResolver
|
||||
*/
|
||||
private $shortNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Configuration\RenamedClassesDataCollector
|
||||
*/
|
||||
private $renamedClassesDataCollector;
|
||||
public function __construct(ShortNameResolver $shortNameResolver, RenamedClassesDataCollector $renamedClassesDataCollector)
|
||||
public function __construct(ShortNameResolver $shortNameResolver)
|
||||
{
|
||||
$this->shortNameResolver = $shortNameResolver;
|
||||
$this->renamedClassesDataCollector = $renamedClassesDataCollector;
|
||||
}
|
||||
public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedObjectType, Node $node) : bool
|
||||
{
|
||||
|
@ -43,7 +36,6 @@ final class FullyQualifiedNameClassNameImportSkipVoter implements ClassNameImpor
|
|||
$shortNamesToFullyQualifiedNames = $this->shortNameResolver->resolveFromFile($file);
|
||||
$fullyQualifiedObjectTypeShortName = $fullyQualifiedObjectType->getShortName();
|
||||
$className = $fullyQualifiedObjectType->getClassName();
|
||||
$removedUses = $this->renamedClassesDataCollector->getOldClasses();
|
||||
foreach ($shortNamesToFullyQualifiedNames as $shortName => $fullyQualifiedName) {
|
||||
if ($fullyQualifiedObjectTypeShortName !== $shortName) {
|
||||
$shortName = $this->cleanShortName($shortName);
|
||||
|
@ -52,10 +44,7 @@ final class FullyQualifiedNameClassNameImportSkipVoter implements ClassNameImpor
|
|||
continue;
|
||||
}
|
||||
$fullyQualifiedName = \ltrim($fullyQualifiedName, '\\');
|
||||
if ($className === $fullyQualifiedName) {
|
||||
return \false;
|
||||
}
|
||||
return !\in_array($fullyQualifiedName, $removedUses, \true);
|
||||
return $className !== $fullyQualifiedName;
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\CodingStyle\ClassNameImport;
|
||||
|
||||
use RectorPrefix202402\Nette\Utils\Reflection;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
|
@ -12,8 +11,6 @@ use PhpParser\Node\Stmt\ClassLike;
|
|||
use PhpParser\Node\Stmt\Namespace_;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
use Rector\CodingStyle\NodeAnalyzer\UseImportNameMatcher;
|
||||
|
@ -24,7 +21,6 @@ use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
|
|||
use Rector\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace;
|
||||
use Rector\ValueObject\Application\File;
|
||||
use ReflectionClass;
|
||||
/**
|
||||
* @see \Rector\Tests\CodingStyle\ClassNameImport\ShortNameResolver\ShortNameResolverTest
|
||||
*/
|
||||
|
@ -40,11 +36,6 @@ final class ShortNameResolver
|
|||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \PHPStan\Reflection\ReflectionProvider
|
||||
*/
|
||||
private $reflectionProvider;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PhpParser\Node\BetterNodeFinder
|
||||
|
@ -64,11 +55,10 @@ final class ShortNameResolver
|
|||
* @var array<string, string[]>
|
||||
*/
|
||||
private $shortNamesByFilePath = [];
|
||||
public function __construct(SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeNameResolver $nodeNameResolver, ReflectionProvider $reflectionProvider, BetterNodeFinder $betterNodeFinder, UseImportNameMatcher $useImportNameMatcher, PhpDocInfoFactory $phpDocInfoFactory)
|
||||
public function __construct(SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeNameResolver $nodeNameResolver, BetterNodeFinder $betterNodeFinder, UseImportNameMatcher $useImportNameMatcher, PhpDocInfoFactory $phpDocInfoFactory)
|
||||
{
|
||||
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
$this->useImportNameMatcher = $useImportNameMatcher;
|
||||
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
||||
|
@ -152,7 +142,6 @@ final class ShortNameResolver
|
|||
*/
|
||||
private function resolveFromStmtsDocBlocks(array $stmts) : array
|
||||
{
|
||||
$classReflection = $this->resolveClassReflection($stmts);
|
||||
$shortNames = [];
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($stmts, function (Node $node) use(&$shortNames) {
|
||||
// speed up for nodes that are
|
||||
|
@ -176,42 +165,22 @@ final class ShortNameResolver
|
|||
});
|
||||
return null;
|
||||
});
|
||||
return $this->fqnizeShortNames($shortNames, $classReflection, $stmts);
|
||||
}
|
||||
/**
|
||||
* @param Node[] $stmts
|
||||
*/
|
||||
private function resolveClassReflection(array $stmts) : ?ClassReflection
|
||||
{
|
||||
$firstClassLike = $this->betterNodeFinder->findFirstInstanceOf($stmts, ClassLike::class);
|
||||
if (!$firstClassLike instanceof ClassLike) {
|
||||
return null;
|
||||
}
|
||||
$className = (string) $this->nodeNameResolver->getName($firstClassLike);
|
||||
if (!$this->reflectionProvider->hasClass($className)) {
|
||||
return null;
|
||||
}
|
||||
return $this->reflectionProvider->getClass($className);
|
||||
return $this->fqnizeShortNames($shortNames, $stmts);
|
||||
}
|
||||
/**
|
||||
* @param string[] $shortNames
|
||||
* @param Stmt[] $stmts
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function fqnizeShortNames(array $shortNames, ?ClassReflection $classReflection, array $stmts) : array
|
||||
private function fqnizeShortNames(array $shortNames, array $stmts) : array
|
||||
{
|
||||
$shortNamesToFullyQualifiedNames = [];
|
||||
$nativeReflectionClass = $classReflection instanceof ClassReflection && !$classReflection->isAnonymous() ? $classReflection->getNativeReflection() : null;
|
||||
foreach ($shortNames as $shortName) {
|
||||
$stmtsMatchedName = $this->useImportNameMatcher->matchNameWithStmts($shortName, $stmts);
|
||||
if ($nativeReflectionClass instanceof ReflectionClass) {
|
||||
$fullyQualifiedName = Reflection::expandClassName($shortName, $nativeReflectionClass);
|
||||
} elseif (\is_string($stmtsMatchedName)) {
|
||||
$fullyQualifiedName = $stmtsMatchedName;
|
||||
} else {
|
||||
$fullyQualifiedName = $shortName;
|
||||
if ($stmtsMatchedName == null) {
|
||||
continue;
|
||||
}
|
||||
$shortNamesToFullyQualifiedNames[$shortName] = $fullyQualifiedName;
|
||||
$shortNamesToFullyQualifiedNames[$shortName] = $stmtsMatchedName;
|
||||
}
|
||||
return $shortNamesToFullyQualifiedNames;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\CodingStyle\Naming;
|
||||
|
||||
use RectorPrefix202402\Nette\Utils\Strings;
|
||||
use RectorPrefix202405\Nette\Utils\Strings;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\CodingStyle\NodeAnalyzer;
|
||||
|
||||
use RectorPrefix202402\Nette\Utils\Strings;
|
||||
use RectorPrefix202405\Nette\Utils\Strings;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\GroupUse;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\CodingStyle\Rector\Catch_;
|
||||
|
||||
use RectorPrefix202402\Nette\Utils\Strings;
|
||||
use RectorPrefix202405\Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
|
|
|
@ -85,17 +85,28 @@ CODE_SAMPLE
|
|||
if (!$classReflection instanceof ClassReflection) {
|
||||
return null;
|
||||
}
|
||||
if ($classReflection->isAnonymous()) {
|
||||
return null;
|
||||
}
|
||||
$parentClassReflections = $classReflection->getParents();
|
||||
if ($parentClassReflections === []) {
|
||||
return null;
|
||||
}
|
||||
$hasChanged = \false;
|
||||
$interfaces = $classReflection->getInterfaces();
|
||||
foreach ($node->getMethods() as $classMethod) {
|
||||
if ($classMethod->isMagic()) {
|
||||
continue;
|
||||
}
|
||||
/** @var string $methodName */
|
||||
$methodName = $this->getName($classMethod->name);
|
||||
if ($classMethod->isPublic()) {
|
||||
foreach ($interfaces as $interface) {
|
||||
if ($interface->hasNativeMethod($methodName)) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($parentClassReflections as $parentClassReflection) {
|
||||
$nativeClassReflection = $parentClassReflection->getNativeReflection();
|
||||
// the class reflection above takes also @method annotations into an account
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\CodingStyle\Rector\Encapsed;
|
||||
|
||||
use RectorPrefix202402\Nette\Utils\Strings;
|
||||
use RectorPrefix202405\Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr;
|
||||
|
|
|
@ -89,6 +89,7 @@ CODE_SAMPLE
|
|||
}
|
||||
\end($node->stmts);
|
||||
$totalKeys = \key($node->stmts);
|
||||
\reset($node->stmts);
|
||||
for ($key = $jumpToKey; $key < $totalKeys; ++$key) {
|
||||
if (!isset($node->stmts[$key], $node->stmts[$key + 1])) {
|
||||
break;
|
||||
|
@ -122,7 +123,7 @@ CODE_SAMPLE
|
|||
}
|
||||
/**
|
||||
* @param int|float $rangeLine
|
||||
* @return int|float
|
||||
* @return float|int
|
||||
*/
|
||||
private function resolveRangeLineFromComment($rangeLine, int $line, int $endLine, Stmt $nextStmt)
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\CodingStyle\Rector\Stmt;
|
||||
|
||||
use RectorPrefix202402\Nette\Utils\Strings;
|
||||
use RectorPrefix202405\Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Stmt\Namespace_;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\CodingStyle\Rector\String_;
|
||||
|
||||
use RectorPrefix202402\Nette\Utils\Strings;
|
||||
use RectorPrefix202405\Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\CodingStyle\Reflection;
|
||||
|
||||
use PHPStan\Reflection\FunctionReflection;
|
||||
use PHPStan\Reflection\MethodReflection;
|
||||
use Rector\FileSystem\FilePathHelper;
|
||||
final class VendorLocationDetector
|
||||
|
@ -20,6 +21,15 @@ final class VendorLocationDetector
|
|||
{
|
||||
$declaringClassReflection = $methodReflection->getDeclaringClass();
|
||||
$fileName = $declaringClassReflection->getFileName();
|
||||
return $this->detect($fileName);
|
||||
}
|
||||
public function detectFunctionReflection(FunctionReflection $functionReflection) : bool
|
||||
{
|
||||
$fileName = $functionReflection->getFileName();
|
||||
return $this->detect($fileName);
|
||||
}
|
||||
private function detect(?string $fileName = null) : bool
|
||||
{
|
||||
// probably internal
|
||||
if ($fileName === null) {
|
||||
return \false;
|
||||
|
|
|
@ -4,6 +4,7 @@ declare (strict_types=1);
|
|||
namespace Rector\DeadCode\NodeAnalyzer;
|
||||
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\NullsafeMethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
|
@ -29,7 +30,7 @@ final class CallCollectionAnalyzer
|
|||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
}
|
||||
/**
|
||||
* @param StaticCall[]|MethodCall[] $calls
|
||||
* @param StaticCall[]|MethodCall[]|NullsafeMethodCall[] $calls
|
||||
*/
|
||||
public function isExists(array $calls, string $classMethodName, string $className) : bool
|
||||
{
|
||||
|
@ -52,14 +53,14 @@ final class CallCollectionAnalyzer
|
|||
return \false;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $call
|
||||
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\NullsafeMethodCall $call
|
||||
*/
|
||||
private function isSelfStatic($call) : bool
|
||||
{
|
||||
return $call instanceof StaticCall && $call->class instanceof Name && \in_array($call->class->toString(), [ObjectReference::SELF, ObjectReference::STATIC], \true);
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall $call
|
||||
* @param \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\NullsafeMethodCall $call
|
||||
*/
|
||||
private function shouldSkip($call, string $classMethodName) : bool
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@ use PhpParser\Node\Expr\Array_;
|
|||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\CallLike;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\NullsafeMethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
|
@ -88,11 +89,15 @@ final class IsClassMethodUsedAnalyzer
|
|||
if ($this->isClassMethodCalledInLocalMethodCall($class, $classMethodName)) {
|
||||
return \true;
|
||||
}
|
||||
// 2. direct static calls
|
||||
// 2. direct null-safe calls
|
||||
if ($this->isClassMethodCalledInLocalNullsafeMethodCall($class, $classMethodName)) {
|
||||
return \true;
|
||||
}
|
||||
// 3. direct static calls
|
||||
if ($this->isClassMethodUsedInLocalStaticCall($class, $classMethodName)) {
|
||||
return \true;
|
||||
}
|
||||
// 3. magic array calls!
|
||||
// 4. magic array calls!
|
||||
if ($this->isClassMethodCalledInLocalArrayCall($class, $classMethod, $scope)) {
|
||||
return \true;
|
||||
}
|
||||
|
@ -113,6 +118,13 @@ final class IsClassMethodUsedAnalyzer
|
|||
$methodCalls = $this->betterNodeFinder->findInstanceOf($class, MethodCall::class);
|
||||
return $this->callCollectionAnalyzer->isExists($methodCalls, $classMethodName, $className);
|
||||
}
|
||||
private function isClassMethodCalledInLocalNullsafeMethodCall(Class_ $class, string $classMethodName) : bool
|
||||
{
|
||||
$className = (string) $this->nodeNameResolver->getName($class);
|
||||
/** @var Node\Expr\NullsafeMethodCall[] $methodCalls */
|
||||
$methodCalls = $this->betterNodeFinder->findInstanceOf($class, NullsafeMethodCall::class);
|
||||
return $this->callCollectionAnalyzer->isExists($methodCalls, $classMethodName, $className);
|
||||
}
|
||||
private function isInArrayMap(Class_ $class, Array_ $array) : bool
|
||||
{
|
||||
if (!$array->getAttribute(ArrayMapArgVisitor::ATTRIBUTE_NAME) instanceof Arg) {
|
||||
|
@ -134,11 +146,12 @@ final class IsClassMethodUsedAnalyzer
|
|||
{
|
||||
/** @var Array_[] $arrays */
|
||||
$arrays = $this->betterNodeFinder->findInstanceOf($class, Array_::class);
|
||||
$classMethodName = $this->nodeNameResolver->getName($classMethod);
|
||||
foreach ($arrays as $array) {
|
||||
if ($this->isInArrayMap($class, $array)) {
|
||||
return \true;
|
||||
}
|
||||
$arrayCallable = $this->arrayCallableMethodMatcher->match($array, $scope);
|
||||
$arrayCallable = $this->arrayCallableMethodMatcher->match($array, $scope, $classMethodName);
|
||||
if ($arrayCallable instanceof ArrayCallableDynamicMethod) {
|
||||
return \true;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Rector\DeadCode\NodeAnalyzer;
|
|||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\NullsafePropertyFetch;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticPropertyFetch;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
|
@ -24,7 +25,7 @@ final class PropertyWriteonlyAnalyzer
|
|||
public function hasClassDynamicPropertyNames(Class_ $class) : bool
|
||||
{
|
||||
return (bool) $this->betterNodeFinder->findFirst($class, static function (Node $node) : bool {
|
||||
if (!$node instanceof PropertyFetch) {
|
||||
if (!$node instanceof PropertyFetch && !$node instanceof NullsafePropertyFetch) {
|
||||
return \false;
|
||||
}
|
||||
// has dynamic name - could be anything
|
||||
|
@ -34,7 +35,7 @@ final class PropertyWriteonlyAnalyzer
|
|||
/**
|
||||
* The property fetches are always only assigned to, nothing else
|
||||
*
|
||||
* @param array<PropertyFetch|StaticPropertyFetch> $propertyFetches
|
||||
* @param array<PropertyFetch|StaticPropertyFetch|NullsafePropertyFetch> $propertyFetches
|
||||
*/
|
||||
public function arePropertyFetchesExclusivelyBeingAssignedTo(array $propertyFetches) : bool
|
||||
{
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\DeadCode\NodeAnalyzer;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
|
||||
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
|
||||
use PhpParser\Node\Expr\Instanceof_;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticPropertyFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use Rector\NodeAnalyzer\ExprAnalyzer;
|
||||
use Rector\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\Reflection\ReflectionResolver;
|
||||
final class SafeLeftTypeBooleanAndOrAnalyzer
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PhpParser\Node\BetterNodeFinder
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeAnalyzer\ExprAnalyzer
|
||||
*/
|
||||
private $exprAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Reflection\ReflectionResolver
|
||||
*/
|
||||
private $reflectionResolver;
|
||||
public function __construct(BetterNodeFinder $betterNodeFinder, ExprAnalyzer $exprAnalyzer, ReflectionResolver $reflectionResolver)
|
||||
{
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
$this->exprAnalyzer = $exprAnalyzer;
|
||||
$this->reflectionResolver = $reflectionResolver;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\BinaryOp\BooleanAnd|\PhpParser\Node\Expr\BinaryOp\BooleanOr $booleanAnd
|
||||
*/
|
||||
public function isSafe($booleanAnd) : bool
|
||||
{
|
||||
$hasNonTypedFromParam = (bool) $this->betterNodeFinder->findFirst($booleanAnd->left, function (Node $node) : bool {
|
||||
return $node instanceof Variable && $this->exprAnalyzer->isNonTypedFromParam($node);
|
||||
});
|
||||
if ($hasNonTypedFromParam) {
|
||||
return \false;
|
||||
}
|
||||
$hasPropertyFetchOrArrayDimFetch = (bool) $this->betterNodeFinder->findFirst($booleanAnd->left, static function (Node $node) : bool {
|
||||
return $node instanceof PropertyFetch || $node instanceof StaticPropertyFetch || $node instanceof ArrayDimFetch;
|
||||
});
|
||||
// get type from Property and ArrayDimFetch is unreliable
|
||||
if ($hasPropertyFetchOrArrayDimFetch) {
|
||||
return \false;
|
||||
}
|
||||
// skip trait this
|
||||
$classReflection = $this->reflectionResolver->resolveClassReflection($booleanAnd);
|
||||
if ($classReflection instanceof ClassReflection && $classReflection->isTrait()) {
|
||||
return !$booleanAnd->left instanceof Instanceof_;
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
|
|||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
|
||||
use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareUnionTypeNode;
|
||||
use Rector\DeadCode\PhpDoc\Guard\StandaloneTypeRemovalGuard;
|
||||
use Rector\DeadCode\TypeNodeAnalyzer\GenericTypeNodeAnalyzer;
|
||||
use Rector\DeadCode\TypeNodeAnalyzer\MixedArrayTypeNodeAnalyzer;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
|
@ -47,7 +48,12 @@ final class DeadParamTagValueNodeAnalyzer
|
|||
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger
|
||||
*/
|
||||
private $phpDocTypeChanger;
|
||||
public function __construct(NodeNameResolver $nodeNameResolver, TypeComparator $typeComparator, GenericTypeNodeAnalyzer $genericTypeNodeAnalyzer, MixedArrayTypeNodeAnalyzer $mixedArrayTypeNodeAnalyzer, ParamAnalyzer $paramAnalyzer, PhpDocTypeChanger $phpDocTypeChanger)
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\DeadCode\PhpDoc\Guard\StandaloneTypeRemovalGuard
|
||||
*/
|
||||
private $standaloneTypeRemovalGuard;
|
||||
public function __construct(NodeNameResolver $nodeNameResolver, TypeComparator $typeComparator, GenericTypeNodeAnalyzer $genericTypeNodeAnalyzer, MixedArrayTypeNodeAnalyzer $mixedArrayTypeNodeAnalyzer, ParamAnalyzer $paramAnalyzer, PhpDocTypeChanger $phpDocTypeChanger, StandaloneTypeRemovalGuard $standaloneTypeRemovalGuard)
|
||||
{
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->typeComparator = $typeComparator;
|
||||
|
@ -55,6 +61,7 @@ final class DeadParamTagValueNodeAnalyzer
|
|||
$this->mixedArrayTypeNodeAnalyzer = $mixedArrayTypeNodeAnalyzer;
|
||||
$this->paramAnalyzer = $paramAnalyzer;
|
||||
$this->phpDocTypeChanger = $phpDocTypeChanger;
|
||||
$this->standaloneTypeRemovalGuard = $standaloneTypeRemovalGuard;
|
||||
}
|
||||
public function isDead(ParamTagValueNode $paramTagValueNode, FunctionLike $functionLike) : bool
|
||||
{
|
||||
|
@ -78,11 +85,15 @@ final class DeadParamTagValueNodeAnalyzer
|
|||
return \false;
|
||||
}
|
||||
if (!$paramTagValueNode->type instanceof BracketsAwareUnionTypeNode) {
|
||||
return \true;
|
||||
return $this->standaloneTypeRemovalGuard->isLegal($paramTagValueNode->type, $param->type);
|
||||
}
|
||||
if ($this->mixedArrayTypeNodeAnalyzer->hasMixedArrayType($paramTagValueNode->type)) {
|
||||
return $this->isAllowedBracketAwareUnion($paramTagValueNode->type);
|
||||
}
|
||||
private function isAllowedBracketAwareUnion(BracketsAwareUnionTypeNode $bracketsAwareUnionTypeNode) : bool
|
||||
{
|
||||
if ($this->mixedArrayTypeNodeAnalyzer->hasMixedArrayType($bracketsAwareUnionTypeNode)) {
|
||||
return \false;
|
||||
}
|
||||
return !$this->genericTypeNodeAnalyzer->hasGenericType($paramTagValueNode->type);
|
||||
return !$this->genericTypeNodeAnalyzer->hasGenericType($bracketsAwareUnionTypeNode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use PhpParser\Node\FunctionLike;
|
|||
use PHPStan\PhpDocParser\Ast\Node;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
|
||||
use Rector\DeadCode\PhpDoc\DeadParamTagValueNodeAnalyzer;
|
||||
|
@ -29,11 +29,11 @@ final class ParamTagRemover
|
|||
$this->deadParamTagValueNodeAnalyzer = $deadParamTagValueNodeAnalyzer;
|
||||
$this->docBlockUpdater = $docBlockUpdater;
|
||||
}
|
||||
public function removeParamTagsIfUseless(PhpDocInfo $phpDocInfo, FunctionLike $functionLike) : bool
|
||||
public function removeParamTagsIfUseless(PhpDocInfo $phpDocInfo, FunctionLike $functionLike, ?Type $type = null) : bool
|
||||
{
|
||||
$hasChanged = \false;
|
||||
$phpDocNodeTraverser = new PhpDocNodeTraverser();
|
||||
$phpDocNodeTraverser->traverseWithCallable($phpDocInfo->getPhpDocNode(), '', function (Node $docNode) use($functionLike, &$hasChanged) : ?int {
|
||||
$phpDocNodeTraverser->traverseWithCallable($phpDocInfo->getPhpDocNode(), '', function (Node $docNode) use($functionLike, &$hasChanged, $type, $phpDocInfo) : ?int {
|
||||
if (!$docNode instanceof PhpDocTagNode) {
|
||||
return null;
|
||||
}
|
||||
|
@ -44,8 +44,12 @@ final class ParamTagRemover
|
|||
if ($docNode->name !== '@param') {
|
||||
return null;
|
||||
}
|
||||
// skip union types
|
||||
if ($docNode->value->type instanceof UnionTypeNode) {
|
||||
$paramType = $phpDocInfo->getParamType($docNode->value->parameterName);
|
||||
if ($type instanceof Type) {
|
||||
if ($type->equals($paramType)) {
|
||||
$hasChanged = \true;
|
||||
return PhpDocNodeTraverser::NODE_REMOVE;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (!$this->deadParamTagValueNodeAnalyzer->isDead($docNode->value, $functionLike)) {
|
||||
|
|
|
@ -14,6 +14,7 @@ use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
|||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
|
||||
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
|
||||
use Rector\DeadCode\PhpDoc\DeadVarTagValueNodeAnalyzer;
|
||||
use Rector\NodeTypeResolver\TypeComparator\TypeComparator;
|
||||
use Rector\PHPStanStaticTypeMapper\DoctrineTypeAnalyzer;
|
||||
final class VarTagRemover
|
||||
{
|
||||
|
@ -42,13 +43,19 @@ final class VarTagRemover
|
|||
* @var \Rector\Comments\NodeDocBlock\DocBlockUpdater
|
||||
*/
|
||||
private $docBlockUpdater;
|
||||
public function __construct(DoctrineTypeAnalyzer $doctrineTypeAnalyzer, PhpDocInfoFactory $phpDocInfoFactory, DeadVarTagValueNodeAnalyzer $deadVarTagValueNodeAnalyzer, PhpDocTypeChanger $phpDocTypeChanger, DocBlockUpdater $docBlockUpdater)
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeTypeResolver\TypeComparator\TypeComparator
|
||||
*/
|
||||
private $typeComparator;
|
||||
public function __construct(DoctrineTypeAnalyzer $doctrineTypeAnalyzer, PhpDocInfoFactory $phpDocInfoFactory, DeadVarTagValueNodeAnalyzer $deadVarTagValueNodeAnalyzer, PhpDocTypeChanger $phpDocTypeChanger, DocBlockUpdater $docBlockUpdater, TypeComparator $typeComparator)
|
||||
{
|
||||
$this->doctrineTypeAnalyzer = $doctrineTypeAnalyzer;
|
||||
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
||||
$this->deadVarTagValueNodeAnalyzer = $deadVarTagValueNodeAnalyzer;
|
||||
$this->phpDocTypeChanger = $phpDocTypeChanger;
|
||||
$this->docBlockUpdater = $docBlockUpdater;
|
||||
$this->typeComparator = $typeComparator;
|
||||
}
|
||||
public function removeVarTagIfUseless(PhpDocInfo $phpDocInfo, Property $property) : bool
|
||||
{
|
||||
|
@ -92,7 +99,15 @@ final class VarTagRemover
|
|||
if ($this->phpDocTypeChanger->isAllowed($varTagValueNode->type)) {
|
||||
return;
|
||||
}
|
||||
// keep subtypes like positive-int
|
||||
if ($this->shouldKeepSubtypes($type, $phpDocInfo->getVarType())) {
|
||||
return;
|
||||
}
|
||||
$phpDocInfo->removeByType(VarTagValueNode::class);
|
||||
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node);
|
||||
}
|
||||
private function shouldKeepSubtypes(Type $type, Type $varType) : bool
|
||||
{
|
||||
return !$this->typeComparator->areTypesEqual($type, $varType) && $this->typeComparator->isSubtype($varType, $type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,10 +95,7 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
// we cannot be sure here
|
||||
if ($this->containsCompactFuncCall($node)) {
|
||||
return null;
|
||||
}
|
||||
if ($this->containsFileIncludes($node)) {
|
||||
if ($this->shouldSkip($stmts)) {
|
||||
return null;
|
||||
}
|
||||
$assignedVariableNamesByStmtPosition = $this->resolvedAssignedVariablesByStmtPosition($stmts);
|
||||
|
@ -165,24 +162,19 @@ CODE_SAMPLE
|
|||
return \false;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
* @param Stmt[] $stmts
|
||||
*/
|
||||
private function containsCompactFuncCall($functionLike) : bool
|
||||
private function shouldSkip(array $stmts) : bool
|
||||
{
|
||||
$compactFuncCall = $this->betterNodeFinder->findFirst($functionLike, function (Node $node) : bool {
|
||||
return (bool) $this->betterNodeFinder->findFirst($stmts, function (Node $node) : bool {
|
||||
if ($node instanceof Include_) {
|
||||
return \true;
|
||||
}
|
||||
if (!$node instanceof FuncCall) {
|
||||
return \false;
|
||||
}
|
||||
return $this->isName($node, 'compact');
|
||||
});
|
||||
return $compactFuncCall instanceof FuncCall;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
*/
|
||||
private function containsFileIncludes($functionLike) : bool
|
||||
{
|
||||
return (bool) $this->betterNodeFinder->findInstancesOf($functionLike, [Include_::class]);
|
||||
}
|
||||
/**
|
||||
* @param array<int, Stmt> $stmts
|
||||
|
|
|
@ -93,7 +93,7 @@ CODE_SAMPLE
|
|||
if (!isset(self::CAST_CLASS_TO_NODE_TYPE[$nodeClass])) {
|
||||
return null;
|
||||
}
|
||||
$nodeType = $this->getType($node->expr);
|
||||
$nodeType = $this->nodeTypeResolver->getNativeType($node->expr);
|
||||
if ($nodeType instanceof MixedType) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ use Rector\Contract\Rector\ConfigurableRectorInterface;
|
|||
use Rector\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix202402\Webmozart\Assert\Assert;
|
||||
use RectorPrefix202405\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @see \Rector\Tests\DeadCode\Rector\ClassLike\RemoveAnnotationRector\RemoveAnnotationRectorTest
|
||||
*/
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue