Updated Rector to commit eb5df4dde7515bbc497af6da84d5f9dbf96399d8

eb5df4dde7 Use vendor-patches main branch (#6453)
This commit is contained in:
Tomas Votruba 2024-11-20 15:58:53 +00:00
parent e23b5045f1
commit 9a4a5b2bc5
1689 changed files with 12969 additions and 16845 deletions

View File

@ -13,7 +13,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
php_version: ['7.2', '7.3', '7.4', '8.0', '8.1'] php_version: ['7.4', '8.0', '8.1']
commands: commands:
- -
name: 'Composer Dependency' name: 'Composer Dependency'

View File

@ -14,7 +14,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
php_version: ['7.2', '7.3', '7.4', '8.0', '8.1'] php_version: ['7.4', '8.0', '8.1']
directory: directory:
- 'e2e/define-constant' - 'e2e/define-constant'
- 'e2e/dont-execute-code' - 'e2e/dont-execute-code'

View File

@ -14,7 +14,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
php_version: ['7.2', '7.3', '7.4', '8.0', '8.1'] php_version: ['7.4', '8.0', '8.1']
directory: directory:
- 'e2e/attributes' - 'e2e/attributes'

View File

@ -11,7 +11,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
php_version: ['7.2', '7.3', '7.4', '8.0', '8.1'] php_version: ['7.4', '8.0', '8.1']
directory: directory:
- 'e2e/global-install' - 'e2e/global-install'

View File

@ -1,31 +0,0 @@
name: End to End tests on PHP 7.2
on:
push:
branches:
- main
jobs:
end_to_end_on_php72:
runs-on: ubuntu-latest
name: End to end test - PHP 7.2 with load ReflectionUnionType stub
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: "7.2"
coverage: none
# wait for deploy to packagist
- run: sleep 40
-
run: composer require rector/rector:dev-main --ansi
working-directory: e2e/reflection-union-php72
-
run: vendor/bin/rector process --ansi
working-directory: e2e/reflection-union-php72

View File

@ -11,7 +11,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
php_version: ['7.3'] php_version: ['7.4']
directory: directory:
- 'e2e/rector-prefixed-rule-test' - 'e2e/rector-prefixed-rule-test'

View File

@ -29,7 +29,7 @@ final class AutoloadIncluder
/** /**
* @var string[] * @var string[]
*/ */
private $alreadyLoadedAutoloadFiles = []; private array $alreadyLoadedAutoloadFiles = [];
public function includeDependencyOrRepositoryVendorAutoloadIfExists() : void public function includeDependencyOrRepositoryVendorAutoloadIfExists() : void
{ {
// Rector's vendor is already loaded // Rector's vendor is already loaded

View File

@ -7,8 +7,8 @@
"bin/rector" "bin/rector"
], ],
"require": { "require": {
"php": "^7.2|^8.0", "php": "^7.4|^8.0",
"phpstan/phpstan": "^1.12.5" "phpstan/phpstan": "^2.0.1"
}, },
"autoload": { "autoload": {
"files": [ "files": [

View File

@ -24,5 +24,4 @@ services:
class: PHPStan\Parser\RichParser class: PHPStan\Parser\RichParser
arguments: arguments:
parser: @currentPhpVersionPhpParser parser: @currentPhpVersionPhpParser
lexer: @currentPhpVersionLexer
autowired: no autowired: no

View File

@ -1,9 +1,3 @@
parameters:
# see https://github.com/rectorphp/rector/issues/3490#issue-634342324
featureToggles:
disableRuntimeReflectionProvider: false
nodeConnectingVisitorCompatibility: false
services: services:
- Rector\NodeTypeResolver\Reflection\BetterReflection\RectorBetterReflectionSourceLocatorFactory - Rector\NodeTypeResolver\Reflection\BetterReflection\RectorBetterReflectionSourceLocatorFactory
- Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocator\IntermediateSourceLocator - Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocator\IntermediateSourceLocator

View File

@ -1,11 +0,0 @@
{
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"require": {
"php": "7.2.*",
"rector/rector": "dev-main"
}
}

View File

@ -1,17 +0,0 @@
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src'
]);
$rectorConfig->skip([
__DIR__ . '/vendor',
]);
$rectorConfig->sets([\Rector\Set\ValueObject\SetList::CODE_QUALITY]);
};

View File

@ -1,14 +0,0 @@
<?php
namespace App;
class Foo {
/**
* @param \DateTime|\DateTimeImmutable $date
* @return string
*/
public function bar($date) {
return $date->format('C');
}
}

View File

@ -12,6 +12,7 @@ require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/KeywordEmulator.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/KeywordEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Comment.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Comment.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinter.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinterAbstract.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinterAbstract.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php';
@ -56,28 +57,30 @@ require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ErrorHandler/Thro
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Internal/DiffElem.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Internal/DiffElem.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Internal/Differ.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Internal/Differ.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Internal/PrintableNewAnonClassNode.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Internal/PrintableNewAnonClassNode.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Internal/TokenPolyfill.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Internal/TokenStream.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Internal/TokenStream.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/JsonDecoder.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/JsonDecoder.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/Emulative.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/Emulative.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/AsymmetricVisibilityTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/AttributeEmulator.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/AttributeEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/CoaleseEqualTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/EnumTokenEmulator.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/EnumTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ExplicitOctalEmulator.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ExplicitOctalEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/FlexibleDocStringEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/FnTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/MatchTokenEmulator.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/MatchTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/NullsafeTokenEmulator.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/NullsafeTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/NumericLiteralSeparatorEmulator.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/PropertyTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReadonlyFunctionTokenEmulator.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReadonlyFunctionTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReadonlyTokenEmulator.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReadonlyTokenEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReverseEmulator.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReverseEmulator.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Modifiers.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NameContext.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NameContext.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Arg.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Arg.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/ArrayItem.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Attribute.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Attribute.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/AttributeGroup.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/AttributeGroup.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/ClosureUse.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Const_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Const_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/DeclareItem.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ArrayDimFetch.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ArrayDimFetch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ArrayItem.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Array_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Array_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ArrowFunction.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ArrowFunction.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Assign.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Assign.php';
@ -135,7 +138,6 @@ require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Un
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ClassConstFetch.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ClassConstFetch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Clone_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Clone_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Closure.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Closure.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ClosureUse.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ConstFetch.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ConstFetch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Empty_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Empty_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Error.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Error.php';
@ -169,16 +171,20 @@ require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Variabl
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/YieldFrom.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/YieldFrom.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Yield_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Yield_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Identifier.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Identifier.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/InterpolatedStringPart.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/IntersectionType.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/IntersectionType.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/MatchArm.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/MatchArm.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Name/FullyQualified.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Name/FullyQualified.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Name/Relative.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Name/Relative.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/NullableType.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/NullableType.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Param.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Param.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/PropertyHook.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/PropertyItem.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/DNumber.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/DNumber.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/Encapsed.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/Encapsed.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/EncapsedStringPart.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/Float_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/LNumber.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/Int_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/InterpolatedString.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Class_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Class_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Dir.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Dir.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/File.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/File.php';
@ -186,8 +192,11 @@ require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/Magic
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Line.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Line.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Method.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Method.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Namespace_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Namespace_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Property.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Trait_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Trait_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/String_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/String_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/StaticVar.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Block.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Break_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Break_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Case_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Case_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Catch_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Catch_.php';
@ -196,7 +205,6 @@ require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/ClassMe
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Class_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Class_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Const_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Const_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Continue_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Continue_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/DeclareDeclare.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Declare_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Declare_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Do_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Do_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Echo_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Echo_.php';
@ -220,12 +228,9 @@ require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Label.p
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Namespace_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Namespace_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Nop.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Nop.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Property.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Property.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/PropertyProperty.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Return_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Return_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/StaticVar.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Static_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Static_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Switch_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Switch_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Throw_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUse.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUse.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Alias.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Alias.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Precedence.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Precedence.php';
@ -236,23 +241,26 @@ require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/UseUse.
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Use_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Use_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/While_.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/While_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/UnionType.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/UnionType.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/UseItem.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/VarLikeIdentifier.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/VarLikeIdentifier.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/VariadicPlaceholder.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/VariadicPlaceholder.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeDumper.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeDumper.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeFinder.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeFinder.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/CloningVisitor.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/CloningVisitor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/CommentAnnotatingVisitor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/FindingVisitor.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/FindingVisitor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/FirstFindingVisitor.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/FirstFindingVisitor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/NameResolver.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/NameResolver.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser/Multiple.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser/Php5.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser/Php7.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser/Php7.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser/Tokens.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Parser/Php8.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ParserFactory.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/ParserFactory.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/PhpVersion.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinter/Standard.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinter/Standard.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Token.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/compatibility_tokens.php';
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Node.php'; require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Node.php';
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/NodeVisitor.php'; require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/NodeVisitor.php';
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Lexer/Lexer.php'; require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Lexer/Lexer.php';
@ -272,7 +280,6 @@ require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExp
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprTrueNode.php'; require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprTrueNode.php';
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstFetchNode.php'; require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstFetchNode.php';
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/DoctrineConstExprStringNode.php'; require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/DoctrineConstExprStringNode.php';
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/QuoteAwareConstExprStringNode.php';
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/NodeTraverser.php'; require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/NodeTraverser.php';
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/NodeVisitor/CloningVisitor.php'; require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/NodeVisitor/CloningVisitor.php';
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/AssertTagMethodValueNode.php'; require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/AssertTagMethodValueNode.php';
@ -338,6 +345,7 @@ require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.ph
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Parser/StringUnescaper.php'; require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Parser/StringUnescaper.php';
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php'; require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php';
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Parser/TypeParser.php'; require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Parser/TypeParser.php';
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/ParserConfig.php';
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Printer/DiffElem.php'; require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Printer/DiffElem.php';
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Printer/Differ.php'; require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Printer/Differ.php';
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Printer/Printer.php'; require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Printer/Printer.php';

View File

@ -20,14 +20,12 @@ final class ArgumentDefaultValueReplacer
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\NodeFactory
*/ */
private $nodeFactory; private NodeFactory $nodeFactory;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(NodeFactory $nodeFactory, ValueResolver $valueResolver) public function __construct(NodeFactory $nodeFactory, ValueResolver $valueResolver)
{ {
$this->nodeFactory = $nodeFactory; $this->nodeFactory = $nodeFactory;

View File

@ -14,9 +14,8 @@ final class ArgumentAddingScope
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/ */
private $nodeNameResolver; private NodeNameResolver $nodeNameResolver;
/** /**
* @api * @api
* @var string * @var string

View File

@ -3,6 +3,7 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\Arguments\NodeAnalyzer; namespace Rector\Arguments\NodeAnalyzer;
use PhpParser\Node;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Param; use PhpParser\Node\Param;
use PHPStan\Type\Type; use PHPStan\Type\Type;
@ -13,19 +14,16 @@ final class ChangedArgumentsDetector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
/** /**
* @readonly * @readonly
* @var \Rector\StaticTypeMapper\StaticTypeMapper
*/ */
private $staticTypeMapper; private StaticTypeMapper $staticTypeMapper;
/** /**
* @readonly * @readonly
* @var \Rector\NodeTypeResolver\TypeComparator\TypeComparator
*/ */
private $typeComparator; private TypeComparator $typeComparator;
public function __construct(ValueResolver $valueResolver, StaticTypeMapper $staticTypeMapper, TypeComparator $typeComparator) public function __construct(ValueResolver $valueResolver, StaticTypeMapper $staticTypeMapper, TypeComparator $typeComparator)
{ {
$this->valueResolver = $valueResolver; $this->valueResolver = $valueResolver;
@ -44,7 +42,7 @@ final class ChangedArgumentsDetector
} }
public function isTypeChanged(Param $param, ?Type $newType) : bool public function isTypeChanged(Param $param, ?Type $newType) : bool
{ {
if ($param->type === null) { if (!$param->type instanceof Node) {
return \false; return \false;
} }
if (!$newType instanceof Type) { if (!$newType instanceof Type) {

View File

@ -37,32 +37,25 @@ final class ArgumentAdderRector extends AbstractRector implements ConfigurableRe
{ {
/** /**
* @readonly * @readonly
* @var \Rector\Arguments\NodeAnalyzer\ArgumentAddingScope
*/ */
private $argumentAddingScope; private ArgumentAddingScope $argumentAddingScope;
/** /**
* @readonly * @readonly
* @var \Rector\Arguments\NodeAnalyzer\ChangedArgumentsDetector
*/ */
private $changedArgumentsDetector; private ChangedArgumentsDetector $changedArgumentsDetector;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\AstResolver
*/ */
private $astResolver; private AstResolver $astResolver;
/** /**
* @readonly * @readonly
* @var \Rector\StaticTypeMapper\StaticTypeMapper
*/ */
private $staticTypeMapper; private StaticTypeMapper $staticTypeMapper;
/** /**
* @var ArgumentAdder[]|ArgumentAdderWithoutDefaultValue[] * @var ArgumentAdder[]|ArgumentAdderWithoutDefaultValue[]
*/ */
private $addedArguments = []; private array $addedArguments = [];
/** private bool $hasChanged = \false;
* @var bool
*/
private $hasChanged = \false;
public function __construct(ArgumentAddingScope $argumentAddingScope, ChangedArgumentsDetector $changedArgumentsDetector, AstResolver $astResolver, StaticTypeMapper $staticTypeMapper) public function __construct(ArgumentAddingScope $argumentAddingScope, ChangedArgumentsDetector $changedArgumentsDetector, AstResolver $astResolver, StaticTypeMapper $staticTypeMapper)
{ {
$this->argumentAddingScope = $argumentAddingScope; $this->argumentAddingScope = $argumentAddingScope;

View File

@ -24,13 +24,12 @@ final class ReplaceArgumentDefaultValueRector extends AbstractRector implements
{ {
/** /**
* @readonly * @readonly
* @var \Rector\Arguments\ArgumentDefaultValueReplacer
*/ */
private $argumentDefaultValueReplacer; private ArgumentDefaultValueReplacer $argumentDefaultValueReplacer;
/** /**
* @var ReplaceArgumentDefaultValue[] * @var ReplaceArgumentDefaultValue[]
*/ */
private $replaceArgumentDefaultValues = []; private array $replaceArgumentDefaultValues = [];
public function __construct(ArgumentDefaultValueReplacer $argumentDefaultValueReplacer) public function __construct(ArgumentDefaultValueReplacer $argumentDefaultValueReplacer)
{ {
$this->argumentDefaultValueReplacer = $argumentDefaultValueReplacer; $this->argumentDefaultValueReplacer = $argumentDefaultValueReplacer;

View File

@ -19,13 +19,12 @@ final class FunctionArgumentDefaultValueReplacerRector extends AbstractRector im
{ {
/** /**
* @readonly * @readonly
* @var \Rector\Arguments\ArgumentDefaultValueReplacer
*/ */
private $argumentDefaultValueReplacer; private ArgumentDefaultValueReplacer $argumentDefaultValueReplacer;
/** /**
* @var ReplaceFuncCallArgumentDefaultValue[] * @var ReplaceFuncCallArgumentDefaultValue[]
*/ */
private $replacedArguments = []; private array $replacedArguments = [];
public function __construct(ArgumentDefaultValueReplacer $argumentDefaultValueReplacer) public function __construct(ArgumentDefaultValueReplacer $argumentDefaultValueReplacer)
{ {
$this->argumentDefaultValueReplacer = $argumentDefaultValueReplacer; $this->argumentDefaultValueReplacer = $argumentDefaultValueReplacer;

View File

@ -20,7 +20,7 @@ final class RemoveMethodCallParamRector extends AbstractRector implements Config
/** /**
* @var RemoveMethodCallParam[] * @var RemoveMethodCallParam[]
*/ */
private $removeMethodCallParams = []; private array $removeMethodCallParams = [];
public function getRuleDefinition() : RuleDefinition public function getRuleDefinition() : RuleDefinition
{ {
return new RuleDefinition('Remove parameter of method call', [new ConfiguredCodeSample(<<<'CODE_SAMPLE' return new RuleDefinition('Remove parameter of method call', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'

View File

@ -10,24 +10,20 @@ final class ArgumentAdder
{ {
/** /**
* @readonly * @readonly
* @var string
*/ */
private $class; private string $class;
/** /**
* @readonly * @readonly
* @var string
*/ */
private $method; private string $method;
/** /**
* @readonly * @readonly
* @var int
*/ */
private $position; private int $position;
/** /**
* @readonly * @readonly
* @var string|null
*/ */
private $argumentName; private ?string $argumentName = null;
/** /**
* @var mixed|null * @var mixed|null
*/ */
@ -39,9 +35,8 @@ final class ArgumentAdder
private $argumentType = null; private $argumentType = null;
/** /**
* @readonly * @readonly
* @var string|null
*/ */
private $scope; private ?string $scope = null;
/** /**
* @param mixed|null $argumentDefaultValue * @param mixed|null $argumentDefaultValue
*/ */

View File

@ -10,24 +10,20 @@ final class ArgumentAdderWithoutDefaultValue
{ {
/** /**
* @readonly * @readonly
* @var string
*/ */
private $class; private string $class;
/** /**
* @readonly * @readonly
* @var string
*/ */
private $method; private string $method;
/** /**
* @readonly * @readonly
* @var int
*/ */
private $position; private int $position;
/** /**
* @readonly * @readonly
* @var string|null
*/ */
private $argumentName; private ?string $argumentName = null;
/** /**
* @readonly * @readonly
* @var \PHPStan\Type\Type|null * @var \PHPStan\Type\Type|null
@ -35,9 +31,8 @@ final class ArgumentAdderWithoutDefaultValue
private $argumentType = null; private $argumentType = null;
/** /**
* @readonly * @readonly
* @var string|null
*/ */
private $scope; private ?string $scope = null;
public function __construct(string $class, string $method, int $position, ?string $argumentName = null, ?\PHPStan\Type\Type $argumentType = null, ?string $scope = null) public function __construct(string $class, string $method, int $position, ?string $argumentName = null, ?\PHPStan\Type\Type $argumentType = null, ?string $scope = null)
{ {
$this->class = $class; $this->class = $class;

View File

@ -9,19 +9,16 @@ final class RemoveMethodCallParam
{ {
/** /**
* @readonly * @readonly
* @var string
*/ */
private $class; private string $class;
/** /**
* @readonly * @readonly
* @var string
*/ */
private $methodName; private string $methodName;
/** /**
* @readonly * @readonly
* @var int
*/ */
private $paramPosition; private int $paramPosition;
public function __construct(string $class, string $methodName, int $paramPosition) public function __construct(string $class, string $methodName, int $paramPosition)
{ {
$this->class = $class; $this->class = $class;

View File

@ -10,19 +10,17 @@ final class ReplaceArgumentDefaultValue implements ReplaceArgumentDefaultValueIn
{ {
/** /**
* @readonly * @readonly
* @var string
*/ */
private $class; private string $class;
/** /**
* @readonly * @readonly
* @var string
*/ */
private $method; private string $method;
/** /**
* @var int<0, max> * @var int<0, max>
* @readonly * @readonly
*/ */
private $position; private int $position;
/** /**
* @readonly * @readonly
* @var mixed * @var mixed

View File

@ -8,14 +8,12 @@ final class ReplaceFuncCallArgumentDefaultValue implements ReplaceArgumentDefaul
{ {
/** /**
* @readonly * @readonly
* @var string
*/ */
private $function; private string $function;
/** /**
* @readonly * @readonly
* @var int
*/ */
private $position; private int $position;
/** /**
* @readonly * @readonly
* @var mixed * @var mixed

View File

@ -3,13 +3,13 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\Carbon\NodeFactory; namespace Rector\Carbon\NodeFactory;
use PhpParser\Node\Scalar\Int_;
use RectorPrefix202411\Nette\Utils\Strings; use RectorPrefix202411\Nette\Utils\Strings;
use PhpParser\Node\Arg; use PhpParser\Node\Arg;
use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Identifier; use PhpParser\Node\Identifier;
use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\String_; use PhpParser\Node\Scalar\String_;
final class CarbonCallFactory final class CarbonCallFactory
{ {
@ -32,7 +32,7 @@ final class CarbonCallFactory
$string->value = Strings::replace($string->value, self::STATIC_DATE_REGEX); $string->value = Strings::replace($string->value, self::STATIC_DATE_REGEX);
// Handle add/sub multiple times // Handle add/sub multiple times
while ($match = Strings::match($string->value, self::PLUS_MINUS_COUNT_REGEX)) { while ($match = Strings::match($string->value, self::PLUS_MINUS_COUNT_REGEX)) {
$methodCall = $this->createModifyMethodCall($carbonCall, new LNumber((int) $match['count']), $match['unit'], $match['operator']); $methodCall = $this->createModifyMethodCall($carbonCall, new Int_((int) $match['count']), $match['unit'], $match['operator']);
if ($methodCall instanceof MethodCall) { if ($methodCall instanceof MethodCall) {
$carbonCall = $methodCall; $carbonCall = $methodCall;
$string->value = Strings::replace($string->value, self::PLUS_MINUS_COUNT_REGEX, '', 1); $string->value = Strings::replace($string->value, self::PLUS_MINUS_COUNT_REGEX, '', 1);
@ -50,7 +50,7 @@ final class CarbonCallFactory
return $carbonCall; return $carbonCall;
} }
// If we fallback to a parse we want to include tomorrow/today/yesterday etc // If we fallback to a parse we want to include tomorrow/today/yesterday etc
if ($currentCall->name instanceof Identifier && $currentCall->name->name != 'now') { if ($currentCall->name instanceof Identifier && $currentCall->name->name !== 'now') {
$rest .= ' ' . $currentCall->name->name; $rest .= ' ' . $currentCall->name->name;
} }
$currentCall->name = new Identifier('parse'); $currentCall->name = new Identifier('parse');
@ -68,7 +68,7 @@ final class CarbonCallFactory
/** /**
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $carbonCall * @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $carbonCall
*/ */
private function createModifyMethodCall($carbonCall, LNumber $countLNumber, string $unit, string $operator) : ?MethodCall private function createModifyMethodCall($carbonCall, Int_ $int, string $unit, string $operator) : ?MethodCall
{ {
switch ($unit) { switch ($unit) {
case 'sec': case 'sec':
@ -120,7 +120,7 @@ final class CarbonCallFactory
return null; return null;
} }
$methodName = $operator . \ucfirst($unit); $methodName = $operator . \ucfirst($unit);
return new MethodCall($carbonCall, new Identifier($methodName), [new Arg($countLNumber)]); return new MethodCall($carbonCall, new Identifier($methodName), [new Arg($int)]);
} }
/** /**
* @param MethodCall[] $callStack * @param MethodCall[] $callStack

View File

@ -20,9 +20,8 @@ final class DateTimeMethodCallToCarbonRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\Carbon\NodeFactory\CarbonCallFactory
*/ */
private $carbonCallFactory; private CarbonCallFactory $carbonCallFactory;
public function __construct(CarbonCallFactory $carbonCallFactory) public function __construct(CarbonCallFactory $carbonCallFactory)
{ {
$this->carbonCallFactory = $carbonCallFactory; $this->carbonCallFactory = $carbonCallFactory;

View File

@ -21,9 +21,8 @@ final class DateTimeInstanceToCarbonRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\Carbon\NodeFactory\CarbonCallFactory
*/ */
private $carbonCallFactory; private CarbonCallFactory $carbonCallFactory;
public function __construct(CarbonCallFactory $carbonCallFactory) public function __construct(CarbonCallFactory $carbonCallFactory)
{ {
$this->carbonCallFactory = $carbonCallFactory; $this->carbonCallFactory = $carbonCallFactory;

View File

@ -5,7 +5,7 @@ namespace Rector\CodeQuality;
use PhpParser\Node\Arg; use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_; use PhpParser\Node\Scalar\String_;
@ -15,9 +15,8 @@ final class CompactConverter
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(ValueResolver $valueResolver) public function __construct(ValueResolver $valueResolver)
{ {
$this->valueResolver = $valueResolver; $this->valueResolver = $valueResolver;

View File

@ -13,9 +13,8 @@ final class ForeachAnalyzer
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Comparing\NodeComparator
*/ */
private $nodeComparator; private NodeComparator $nodeComparator;
public function __construct(NodeComparator $nodeComparator) public function __construct(NodeComparator $nodeComparator)
{ {
$this->nodeComparator = $nodeComparator; $this->nodeComparator = $nodeComparator;

View File

@ -3,6 +3,7 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\CodeQuality\NodeAnalyzer; namespace Rector\CodeQuality\NodeAnalyzer;
use PhpParser\NodeVisitor;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Assign;
@ -13,7 +14,6 @@ use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Function_; use PhpParser\Node\Stmt\Function_;
use PhpParser\NodeTraverser;
use PHPStan\Analyser\Scope; use PHPStan\Analyser\Scope;
use PHPStan\Type\MixedType; use PHPStan\Type\MixedType;
use PHPStan\Type\Type; use PHPStan\Type\Type;
@ -28,34 +28,28 @@ final class LocalPropertyAnalyzer
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser
*/ */
private $simpleCallableNodeTraverser; private SimpleCallableNodeTraverser $simpleCallableNodeTraverser;
/** /**
* @readonly * @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/ */
private $nodeNameResolver; private NodeNameResolver $nodeNameResolver;
/** /**
* @readonly * @readonly
* @var \Rector\CodeQuality\TypeResolver\ArrayDimFetchTypeResolver
*/ */
private $arrayDimFetchTypeResolver; private ArrayDimFetchTypeResolver $arrayDimFetchTypeResolver;
/** /**
* @readonly * @readonly
* @var \Rector\NodeTypeResolver\NodeTypeResolver
*/ */
private $nodeTypeResolver; private NodeTypeResolver $nodeTypeResolver;
/** /**
* @readonly * @readonly
* @var \Rector\NodeAnalyzer\PropertyFetchAnalyzer
*/ */
private $propertyFetchAnalyzer; private PropertyFetchAnalyzer $propertyFetchAnalyzer;
/** /**
* @readonly * @readonly
* @var \Rector\NodeTypeResolver\PHPStan\Type\TypeFactory
*/ */
private $typeFactory; private TypeFactory $typeFactory;
/** /**
* @var string * @var string
*/ */
@ -77,20 +71,20 @@ final class LocalPropertyAnalyzer
$fetchedLocalPropertyNameToTypes = []; $fetchedLocalPropertyNameToTypes = [];
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($class->getMethods(), function (Node $node) use(&$fetchedLocalPropertyNameToTypes) : ?int { $this->simpleCallableNodeTraverser->traverseNodesWithCallable($class->getMethods(), function (Node $node) use(&$fetchedLocalPropertyNameToTypes) : ?int {
if ($this->shouldSkip($node)) { if ($this->shouldSkip($node)) {
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
} }
if ($node instanceof Assign && ($node->var instanceof PropertyFetch || $node->var instanceof ArrayDimFetch)) { if ($node instanceof Assign && ($node->var instanceof PropertyFetch || $node->var instanceof ArrayDimFetch)) {
$propertyFetch = $node->var; $propertyFetch = $node->var;
$propertyName = $this->resolvePropertyName($propertyFetch instanceof ArrayDimFetch ? $propertyFetch->var : $propertyFetch); $propertyName = $this->resolvePropertyName($propertyFetch instanceof ArrayDimFetch ? $propertyFetch->var : $propertyFetch);
if ($propertyName === null) { if ($propertyName === null) {
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
} }
if ($propertyFetch instanceof ArrayDimFetch) { if ($propertyFetch instanceof ArrayDimFetch) {
$fetchedLocalPropertyNameToTypes[$propertyName][] = $this->arrayDimFetchTypeResolver->resolve($propertyFetch, $node); $fetchedLocalPropertyNameToTypes[$propertyName][] = $this->arrayDimFetchTypeResolver->resolve($propertyFetch, $node);
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
} }
$fetchedLocalPropertyNameToTypes[$propertyName][] = $this->nodeTypeResolver->getType($node->expr); $fetchedLocalPropertyNameToTypes[$propertyName][] = $this->nodeTypeResolver->getType($node->expr);
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
} }
$propertyName = $this->resolvePropertyName($node); $propertyName = $this->resolvePropertyName($node);
if ($propertyName === null) { if ($propertyName === null) {

View File

@ -17,14 +17,12 @@ final class VariableDimFetchAssignResolver
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Comparing\NodeComparator
*/ */
private $nodeComparator; private NodeComparator $nodeComparator;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\BetterNodeFinder
*/ */
private $betterNodeFinder; private BetterNodeFinder $betterNodeFinder;
public function __construct(NodeComparator $nodeComparator, BetterNodeFinder $betterNodeFinder) public function __construct(NodeComparator $nodeComparator, BetterNodeFinder $betterNodeFinder)
{ {
$this->nodeComparator = $nodeComparator; $this->nodeComparator = $nodeComparator;
@ -68,9 +66,7 @@ final class VariableDimFetchAssignResolver
if (!$this->nodeComparator->areNodesEqual($arrayDimFetch->var, $variable)) { if (!$this->nodeComparator->areNodesEqual($arrayDimFetch->var, $variable)) {
return null; return null;
} }
$isFoundInExpr = (bool) $this->betterNodeFinder->findFirst($assign->expr, function (Node $subNode) use($variable) : bool { $isFoundInExpr = (bool) $this->betterNodeFinder->findFirst($assign->expr, fn(Node $subNode): bool => $this->nodeComparator->areNodesEqual($subNode, $variable));
return $this->nodeComparator->areNodesEqual($subNode, $variable);
});
if ($isFoundInExpr) { if ($isFoundInExpr) {
return null; return null;
} }

View File

@ -3,17 +3,16 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\CodeQuality\NodeFactory; namespace Rector\CodeQuality\NodeFactory;
use PhpParser\Node\Stmt\Class_; use PhpParser\Modifiers;
use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\PropertyProperty; use PhpParser\Node\PropertyItem;
use PHPStan\Type\Type; use PHPStan\Type\Type;
final class MissingPropertiesFactory final class MissingPropertiesFactory
{ {
/** /**
* @readonly * @readonly
* @var \Rector\CodeQuality\NodeFactory\PropertyTypeDecorator
*/ */
private $propertyTypeDecorator; private \Rector\CodeQuality\NodeFactory\PropertyTypeDecorator $propertyTypeDecorator;
public function __construct(\Rector\CodeQuality\NodeFactory\PropertyTypeDecorator $propertyTypeDecorator) public function __construct(\Rector\CodeQuality\NodeFactory\PropertyTypeDecorator $propertyTypeDecorator)
{ {
$this->propertyTypeDecorator = $propertyTypeDecorator; $this->propertyTypeDecorator = $propertyTypeDecorator;
@ -30,7 +29,7 @@ final class MissingPropertiesFactory
if (!\in_array($propertyName, $propertyNamesToComplete, \true)) { if (!\in_array($propertyName, $propertyNamesToComplete, \true)) {
continue; continue;
} }
$property = new Property(Class_::MODIFIER_PUBLIC, [new PropertyProperty($propertyName)]); $property = new Property(Modifiers::PUBLIC, [new PropertyItem($propertyName)]);
$this->propertyTypeDecorator->decorateProperty($property, $propertyType); $this->propertyTypeDecorator->decorateProperty($property, $propertyType);
$newProperties[] = $property; $newProperties[] = $property;
} }

View File

@ -12,19 +12,16 @@ final class PropertyTypeDecorator
{ {
/** /**
* @readonly * @readonly
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger
*/ */
private $phpDocTypeChanger; private PhpDocTypeChanger $phpDocTypeChanger;
/** /**
* @readonly * @readonly
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
*/ */
private $phpDocInfoFactory; private PhpDocInfoFactory $phpDocInfoFactory;
/** /**
* @readonly * @readonly
* @var \Rector\Privatization\TypeManipulator\TypeNormalizer
*/ */
private $typeNormalizer; private TypeNormalizer $typeNormalizer;
public function __construct(PhpDocTypeChanger $phpDocTypeChanger, PhpDocInfoFactory $phpDocInfoFactory, TypeNormalizer $typeNormalizer) public function __construct(PhpDocTypeChanger $phpDocTypeChanger, PhpDocInfoFactory $phpDocInfoFactory, TypeNormalizer $typeNormalizer)
{ {
$this->phpDocTypeChanger = $phpDocTypeChanger; $this->phpDocTypeChanger = $phpDocTypeChanger;

View File

@ -3,6 +3,7 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\CodeQuality\NodeFactory; namespace Rector\CodeQuality\NodeFactory;
use PhpParser\Modifiers;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\ComplexType; use PhpParser\Node\ComplexType;
use PhpParser\Node\Identifier; use PhpParser\Node\Identifier;
@ -10,7 +11,7 @@ use PhpParser\Node\Name;
use PhpParser\Node\NullableType; use PhpParser\Node\NullableType;
use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\PropertyProperty; use PhpParser\Node\PropertyItem;
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\StaticTypeMapper\StaticTypeMapper;
@ -18,18 +19,17 @@ final class TypedPropertyFactory
{ {
/** /**
* @readonly * @readonly
* @var \Rector\StaticTypeMapper\StaticTypeMapper
*/ */
private $staticTypeMapper; private StaticTypeMapper $staticTypeMapper;
public function __construct(StaticTypeMapper $staticTypeMapper) public function __construct(StaticTypeMapper $staticTypeMapper)
{ {
$this->staticTypeMapper = $staticTypeMapper; $this->staticTypeMapper = $staticTypeMapper;
} }
public function createFromPropertyTagValueNode(PropertyTagValueNode $propertyTagValueNode, Class_ $class, string $propertyName) : Property public function createFromPropertyTagValueNode(PropertyTagValueNode $propertyTagValueNode, Class_ $class, string $propertyName) : Property
{ {
$propertyProperty = new PropertyProperty($propertyName); $propertyItem = new PropertyItem($propertyName);
$propertyTypeNode = $this->createPropertyTypeNode($propertyTagValueNode, $class); $propertyTypeNode = $this->createPropertyTypeNode($propertyTagValueNode, $class);
return new Property(Class_::MODIFIER_PRIVATE, [$propertyProperty], [], $propertyTypeNode); return new Property(Modifiers::PRIVATE, [$propertyItem], [], $propertyTypeNode);
} }
/** /**
* @return \PhpParser\Node\Name|\PhpParser\Node\ComplexType|\PhpParser\Node\Identifier|null * @return \PhpParser\Node\Name|\PhpParser\Node\ComplexType|\PhpParser\Node\Identifier|null

View File

@ -19,24 +19,20 @@ final class ExprBoolCaster
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeTypeResolver\NodeTypeResolver
*/ */
private $nodeTypeResolver; private NodeTypeResolver $nodeTypeResolver;
/** /**
* @readonly * @readonly
* @var \Rector\PHPStanStaticTypeMapper\Utils\TypeUnwrapper
*/ */
private $typeUnwrapper; private TypeUnwrapper $typeUnwrapper;
/** /**
* @readonly * @readonly
* @var \Rector\NodeTypeResolver\PHPStan\Type\StaticTypeAnalyzer
*/ */
private $staticTypeAnalyzer; private StaticTypeAnalyzer $staticTypeAnalyzer;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\NodeFactory
*/ */
private $nodeFactory; private NodeFactory $nodeFactory;
public function __construct(NodeTypeResolver $nodeTypeResolver, TypeUnwrapper $typeUnwrapper, StaticTypeAnalyzer $staticTypeAnalyzer, NodeFactory $nodeFactory) public function __construct(NodeTypeResolver $nodeTypeResolver, TypeUnwrapper $typeUnwrapper, StaticTypeAnalyzer $staticTypeAnalyzer, NodeFactory $nodeFactory)
{ {
$this->nodeTypeResolver = $nodeTypeResolver; $this->nodeTypeResolver = $nodeTypeResolver;

View File

@ -17,9 +17,8 @@ final class CombinedAssignRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\AssignAndBinaryMap
*/ */
private $assignAndBinaryMap; private AssignAndBinaryMap $assignAndBinaryMap;
public function __construct(AssignAndBinaryMap $assignAndBinaryMap) public function __construct(AssignAndBinaryMap $assignAndBinaryMap)
{ {
$this->assignAndBinaryMap = $assignAndBinaryMap; $this->assignAndBinaryMap = $assignAndBinaryMap;

View File

@ -21,9 +21,8 @@ final class SimplifyEmptyArrayCheckRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeManipulator\BinaryOpManipulator
*/ */
private $binaryOpManipulator; private BinaryOpManipulator $binaryOpManipulator;
public function __construct(BinaryOpManipulator $binaryOpManipulator) public function __construct(BinaryOpManipulator $binaryOpManipulator)
{ {
$this->binaryOpManipulator = $binaryOpManipulator; $this->binaryOpManipulator = $binaryOpManipulator;

View File

@ -18,9 +18,8 @@ final class SimplifyDeMorganBinaryRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeManipulator\BinaryOpManipulator
*/ */
private $binaryOpManipulator; private BinaryOpManipulator $binaryOpManipulator;
public function __construct(BinaryOpManipulator $binaryOpManipulator) public function __construct(BinaryOpManipulator $binaryOpManipulator)
{ {
$this->binaryOpManipulator = $binaryOpManipulator; $this->binaryOpManipulator = $binaryOpManipulator;

View File

@ -3,16 +3,16 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\CodeQuality\Rector\Catch_; namespace Rector\CodeQuality\Rector\Catch_;
use PhpParser\NodeVisitor;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Arg; use PhpParser\Node\Arg;
use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\New_; use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\Throw_;
use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier; use PhpParser\Node\Identifier;
use PhpParser\Node\Name; use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Catch_; use PhpParser\Node\Stmt\Catch_;
use PhpParser\Node\Stmt\Throw_;
use PhpParser\NodeTraverser;
use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Reflection\ReflectionProvider; use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\ObjectType; use PHPStan\Type\ObjectType;
@ -29,9 +29,8 @@ final class ThrowWithPreviousExceptionRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \PHPStan\Reflection\ReflectionProvider
*/ */
private $reflectionProvider; private ReflectionProvider $reflectionProvider;
/** /**
* @var int * @var int
*/ */
@ -142,7 +141,7 @@ CODE_SAMPLE
// null the node, to fix broken format preserving printers, see https://github.com/rectorphp/rector/issues/5576 // null the node, to fix broken format preserving printers, see https://github.com/rectorphp/rector/issues/5576
$new->setAttribute(AttributeKey::ORIGINAL_NODE, null); $new->setAttribute(AttributeKey::ORIGINAL_NODE, null);
// nothing more to add // nothing more to add
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
} }
private function resolveExceptionArgumentPosition(Name $exceptionName) : ?int private function resolveExceptionArgumentPosition(Name $exceptionName) : ?int
{ {
@ -160,8 +159,8 @@ CODE_SAMPLE
return self::DEFAULT_EXCEPTION_ARGUMENT_POSITION; return self::DEFAULT_EXCEPTION_ARGUMENT_POSITION;
} }
$extendedMethodReflection = $classReflection->getConstructor(); $extendedMethodReflection = $classReflection->getConstructor();
$parametersAcceptorWithPhpDocs = ParametersAcceptorSelector::combineAcceptors($extendedMethodReflection->getVariants()); $extendedParametersAcceptor = ParametersAcceptorSelector::combineAcceptors($extendedMethodReflection->getVariants());
foreach ($parametersAcceptorWithPhpDocs->getParameters() as $position => $parameterReflectionWithPhpDoc) { foreach ($extendedParametersAcceptor->getParameters() as $position => $parameterReflectionWithPhpDoc) {
$parameterType = $parameterReflectionWithPhpDoc->getType(); $parameterType = $parameterReflectionWithPhpDoc->getType();
$className = ClassNameFromObjectTypeResolver::resolve($parameterReflectionWithPhpDoc->getType()); $className = ClassNameFromObjectTypeResolver::resolve($parameterReflectionWithPhpDoc->getType());
if ($className === null) { if ($className === null) {

View File

@ -3,6 +3,7 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\CodeQuality\Rector\ClassMethod; namespace Rector\CodeQuality\Rector\ClassMethod;
use PhpParser\NodeVisitor;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Closure;
@ -12,7 +13,6 @@ use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_; use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Return_; use PhpParser\Node\Stmt\Return_;
use PhpParser\NodeTraverser;
use PHPStan\Type\NullType; use PHPStan\Type\NullType;
use PHPStan\Type\UnionType; use PHPStan\Type\UnionType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
@ -31,29 +31,24 @@ final class ExplicitReturnNullRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\TypeDeclaration\TypeInferer\SilentVoidResolver
*/ */
private $silentVoidResolver; private SilentVoidResolver $silentVoidResolver;
/** /**
* @readonly * @readonly
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
*/ */
private $phpDocInfoFactory; private PhpDocInfoFactory $phpDocInfoFactory;
/** /**
* @readonly * @readonly
* @var \Rector\NodeTypeResolver\PHPStan\Type\TypeFactory
*/ */
private $typeFactory; private TypeFactory $typeFactory;
/** /**
* @readonly * @readonly
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger
*/ */
private $phpDocTypeChanger; private PhpDocTypeChanger $phpDocTypeChanger;
/** /**
* @readonly * @readonly
* @var \Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer
*/ */
private $returnTypeInferer; private ReturnTypeInferer $returnTypeInferer;
public function __construct(SilentVoidResolver $silentVoidResolver, PhpDocInfoFactory $phpDocInfoFactory, TypeFactory $typeFactory, PhpDocTypeChanger $phpDocTypeChanger, ReturnTypeInferer $returnTypeInferer) public function __construct(SilentVoidResolver $silentVoidResolver, PhpDocInfoFactory $phpDocInfoFactory, TypeFactory $typeFactory, PhpDocTypeChanger $phpDocTypeChanger, ReturnTypeInferer $returnTypeInferer)
{ {
$this->silentVoidResolver = $silentVoidResolver; $this->silentVoidResolver = $silentVoidResolver;
@ -122,7 +117,7 @@ CODE_SAMPLE
$hasChanged = \false; $hasChanged = \false;
$this->traverseNodesWithCallable((array) $node->stmts, static function (Node $node) use(&$hasChanged) { $this->traverseNodesWithCallable((array) $node->stmts, static function (Node $node) use(&$hasChanged) {
if ($node instanceof Class_ || $node instanceof Function_ || $node instanceof Closure) { if ($node instanceof Class_ || $node instanceof Function_ || $node instanceof Closure) {
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
} }
if ($node instanceof Return_ && !$node->expr instanceof Expr) { if ($node instanceof Return_ && !$node->expr instanceof Expr) {
$hasChanged = \true; $hasChanged = \true;

View File

@ -6,7 +6,7 @@ namespace Rector\CodeQuality\Rector\ClassMethod;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt; use PhpParser\Node\Stmt;
@ -27,14 +27,12 @@ final class InlineArrayReturnAssignRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\CodeQuality\NodeAnalyzer\VariableDimFetchAssignResolver
*/ */
private $variableDimFetchAssignResolver; private VariableDimFetchAssignResolver $variableDimFetchAssignResolver;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(VariableDimFetchAssignResolver $variableDimFetchAssignResolver, ValueResolver $valueResolver) public function __construct(VariableDimFetchAssignResolver $variableDimFetchAssignResolver, ValueResolver $valueResolver)
{ {
$this->variableDimFetchAssignResolver = $variableDimFetchAssignResolver; $this->variableDimFetchAssignResolver = $variableDimFetchAssignResolver;
@ -150,9 +148,7 @@ CODE_SAMPLE
*/ */
private function areAssignExclusiveToDimFetch(array $stmts) : bool private function areAssignExclusiveToDimFetch(array $stmts) : bool
{ {
\end($stmts); $lastKey = \array_key_last($stmts);
$lastKey = \key($stmts);
\reset($stmts);
foreach ($stmts as $key => $stmt) { foreach ($stmts as $key => $stmt) {
if ($key === $lastKey) { if ($key === $lastKey) {
// skip last item // skip last item

View File

@ -3,6 +3,7 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\CodeQuality\Rector\ClassMethod; namespace Rector\CodeQuality\Rector\ClassMethod;
use PhpParser\NodeVisitor;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Closure;
@ -11,7 +12,6 @@ use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\NodeTraverser;
use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\ClassReflection;
use Rector\Privatization\NodeManipulator\VisibilityManipulator; use Rector\Privatization\NodeManipulator\VisibilityManipulator;
use Rector\Privatization\VisibilityGuard\ClassMethodVisibilityGuard; use Rector\Privatization\VisibilityGuard\ClassMethodVisibilityGuard;
@ -26,19 +26,16 @@ final class LocallyCalledStaticMethodToNonStaticRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\Privatization\VisibilityGuard\ClassMethodVisibilityGuard
*/ */
private $classMethodVisibilityGuard; private ClassMethodVisibilityGuard $classMethodVisibilityGuard;
/** /**
* @readonly * @readonly
* @var \Rector\Privatization\NodeManipulator\VisibilityManipulator
*/ */
private $visibilityManipulator; private VisibilityManipulator $visibilityManipulator;
/** /**
* @readonly * @readonly
* @var \Rector\Reflection\ReflectionResolver
*/ */
private $reflectionResolver; private ReflectionResolver $reflectionResolver;
public function __construct(ClassMethodVisibilityGuard $classMethodVisibilityGuard, VisibilityManipulator $visibilityManipulator, ReflectionResolver $reflectionResolver) public function __construct(ClassMethodVisibilityGuard $classMethodVisibilityGuard, VisibilityManipulator $visibilityManipulator, ReflectionResolver $reflectionResolver)
{ {
$this->classMethodVisibilityGuard = $classMethodVisibilityGuard; $this->classMethodVisibilityGuard = $classMethodVisibilityGuard;
@ -134,10 +131,10 @@ CODE_SAMPLE
return null; return null;
} }
$shouldSkip = \true; $shouldSkip = \true;
return NodeTraverser::STOP_TRAVERSAL; return NodeVisitor::STOP_TRAVERSAL;
}); });
if ($shouldSkip) { if ($shouldSkip) {
return NodeTraverser::STOP_TRAVERSAL; return NodeVisitor::STOP_TRAVERSAL;
} }
return null; return null;
} }
@ -188,7 +185,7 @@ CODE_SAMPLE
return null; return null;
} }
$isInsideStaticClassMethod = \true; $isInsideStaticClassMethod = \true;
return NodeTraverser::STOP_TRAVERSAL; return NodeVisitor::STOP_TRAVERSAL;
}); });
if ($isInsideStaticClassMethod) { if ($isInsideStaticClassMethod) {
return $isInsideStaticClassMethod; return $isInsideStaticClassMethod;

View File

@ -30,24 +30,20 @@ final class OptionalParametersAfterRequiredRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\Php80\NodeResolver\RequireOptionalParamResolver
*/ */
private $requireOptionalParamResolver; private RequireOptionalParamResolver $requireOptionalParamResolver;
/** /**
* @readonly * @readonly
* @var \Rector\Php80\NodeResolver\ArgumentSorter
*/ */
private $argumentSorter; private ArgumentSorter $argumentSorter;
/** /**
* @readonly * @readonly
* @var \Rector\Reflection\ReflectionResolver
*/ */
private $reflectionResolver; private ReflectionResolver $reflectionResolver;
/** /**
* @readonly * @readonly
* @var \Rector\CodingStyle\Reflection\VendorLocationDetector
*/ */
private $vendorLocationDetector; private VendorLocationDetector $vendorLocationDetector;
/** /**
* @var string * @var string
*/ */

View File

@ -27,39 +27,32 @@ final class CompleteDynamicPropertiesRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\CodeQuality\NodeFactory\MissingPropertiesFactory
*/ */
private $missingPropertiesFactory; private MissingPropertiesFactory $missingPropertiesFactory;
/** /**
* @readonly * @readonly
* @var \Rector\CodeQuality\NodeAnalyzer\LocalPropertyAnalyzer
*/ */
private $localPropertyAnalyzer; private LocalPropertyAnalyzer $localPropertyAnalyzer;
/** /**
* @readonly * @readonly
* @var \Rector\CodeQuality\NodeAnalyzer\ClassLikeAnalyzer
*/ */
private $classLikeAnalyzer; private ClassLikeAnalyzer $classLikeAnalyzer;
/** /**
* @readonly * @readonly
* @var \PHPStan\Reflection\ReflectionProvider
*/ */
private $reflectionProvider; private ReflectionProvider $reflectionProvider;
/** /**
* @readonly * @readonly
* @var \Rector\NodeAnalyzer\ClassAnalyzer
*/ */
private $classAnalyzer; private ClassAnalyzer $classAnalyzer;
/** /**
* @readonly * @readonly
* @var \Rector\NodeAnalyzer\PropertyPresenceChecker
*/ */
private $propertyPresenceChecker; private PropertyPresenceChecker $propertyPresenceChecker;
/** /**
* @readonly * @readonly
* @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer
*/ */
private $phpAttributeAnalyzer; private PhpAttributeAnalyzer $phpAttributeAnalyzer;
public function __construct(MissingPropertiesFactory $missingPropertiesFactory, LocalPropertyAnalyzer $localPropertyAnalyzer, ClassLikeAnalyzer $classLikeAnalyzer, ReflectionProvider $reflectionProvider, ClassAnalyzer $classAnalyzer, PropertyPresenceChecker $propertyPresenceChecker, PhpAttributeAnalyzer $phpAttributeAnalyzer) public function __construct(MissingPropertiesFactory $missingPropertiesFactory, LocalPropertyAnalyzer $localPropertyAnalyzer, ClassLikeAnalyzer $classLikeAnalyzer, ReflectionProvider $reflectionProvider, ClassAnalyzer $classAnalyzer, PropertyPresenceChecker $propertyPresenceChecker, PhpAttributeAnalyzer $phpAttributeAnalyzer)
{ {
$this->missingPropertiesFactory = $missingPropertiesFactory; $this->missingPropertiesFactory = $missingPropertiesFactory;

View File

@ -31,39 +31,32 @@ final class DynamicDocBlockPropertyToNativePropertyRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer
*/ */
private $phpAttributeAnalyzer; private PhpAttributeAnalyzer $phpAttributeAnalyzer;
/** /**
* @readonly * @readonly
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
*/ */
private $phpDocInfoFactory; private PhpDocInfoFactory $phpDocInfoFactory;
/** /**
* @readonly * @readonly
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover
*/ */
private $phpDocTagRemover; private PhpDocTagRemover $phpDocTagRemover;
/** /**
* @readonly * @readonly
* @var \Rector\Comments\NodeDocBlock\DocBlockUpdater
*/ */
private $docBlockUpdater; private DocBlockUpdater $docBlockUpdater;
/** /**
* @readonly * @readonly
* @var \Rector\CodeQuality\NodeFactory\TypedPropertyFactory
*/ */
private $typedPropertyFactory; private TypedPropertyFactory $typedPropertyFactory;
/** /**
* @readonly * @readonly
* @var \Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer
*/ */
private $testsNodeAnalyzer; private TestsNodeAnalyzer $testsNodeAnalyzer;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(PhpAttributeAnalyzer $phpAttributeAnalyzer, PhpDocInfoFactory $phpDocInfoFactory, PhpDocTagRemover $phpDocTagRemover, DocBlockUpdater $docBlockUpdater, TypedPropertyFactory $typedPropertyFactory, TestsNodeAnalyzer $testsNodeAnalyzer, ValueResolver $valueResolver) public function __construct(PhpAttributeAnalyzer $phpAttributeAnalyzer, PhpDocInfoFactory $phpDocInfoFactory, PhpDocTagRemover $phpDocTagRemover, DocBlockUpdater $docBlockUpdater, TypedPropertyFactory $typedPropertyFactory, TestsNodeAnalyzer $testsNodeAnalyzer, ValueResolver $valueResolver)
{ {
$this->phpAttributeAnalyzer = $phpAttributeAnalyzer; $this->phpAttributeAnalyzer = $phpAttributeAnalyzer;
@ -173,10 +166,10 @@ CODE_SAMPLE
continue; continue;
} }
// is property already defined? // is property already defined?
if ($class->getProperty($propertyName)) { if ($class->getProperty($propertyName) instanceof Property) {
// improve exising one type if needed // improve exising one type if needed
$existingProperty = $class->getProperty($propertyName); $existingProperty = $class->getProperty($propertyName);
if ($existingProperty->type !== null) { if ($existingProperty->type instanceof Node) {
continue; continue;
} }
$defaultValue = $existingProperty->props[0]->default; $defaultValue = $existingProperty->props[0]->default;

View File

@ -24,9 +24,8 @@ final class InlineConstructorDefaultToPropertyRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeAnalyzer\ExprAnalyzer
*/ */
private $exprAnalyzer; private ExprAnalyzer $exprAnalyzer;
public function __construct(ExprAnalyzer $exprAnalyzer) public function __construct(ExprAnalyzer $exprAnalyzer)
{ {
$this->exprAnalyzer = $exprAnalyzer; $this->exprAnalyzer = $exprAnalyzer;

View File

@ -35,29 +35,24 @@ final class SimplifyEmptyCheckOnEmptyArrayRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeAnalyzer\ExprAnalyzer
*/ */
private $exprAnalyzer; private ExprAnalyzer $exprAnalyzer;
/** /**
* @readonly * @readonly
* @var \Rector\Reflection\ReflectionResolver
*/ */
private $reflectionResolver; private ReflectionResolver $reflectionResolver;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\AstResolver
*/ */
private $astResolver; private AstResolver $astResolver;
/** /**
* @readonly * @readonly
* @var \Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\AllAssignNodePropertyTypeInferer
*/ */
private $allAssignNodePropertyTypeInferer; private AllAssignNodePropertyTypeInferer $allAssignNodePropertyTypeInferer;
/** /**
* @readonly * @readonly
* @var \Rector\Php\ReservedKeywordAnalyzer
*/ */
private $reservedKeywordAnalyzer; private ReservedKeywordAnalyzer $reservedKeywordAnalyzer;
public function __construct(ExprAnalyzer $exprAnalyzer, ReflectionResolver $reflectionResolver, AstResolver $astResolver, AllAssignNodePropertyTypeInferer $allAssignNodePropertyTypeInferer, ReservedKeywordAnalyzer $reservedKeywordAnalyzer) public function __construct(ExprAnalyzer $exprAnalyzer, ReflectionResolver $reflectionResolver, AstResolver $astResolver, AllAssignNodePropertyTypeInferer $allAssignNodePropertyTypeInferer, ReservedKeywordAnalyzer $reservedKeywordAnalyzer)
{ {
$this->exprAnalyzer = $exprAnalyzer; $this->exprAnalyzer = $exprAnalyzer;

View File

@ -22,9 +22,8 @@ final class InlineIfToExplicitIfRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeManipulator\BinaryOpManipulator
*/ */
private $binaryOpManipulator; private BinaryOpManipulator $binaryOpManipulator;
public function __construct(BinaryOpManipulator $binaryOpManipulator) public function __construct(BinaryOpManipulator $binaryOpManipulator)
{ {
$this->binaryOpManipulator = $binaryOpManipulator; $this->binaryOpManipulator = $binaryOpManipulator;

View File

@ -20,9 +20,8 @@ final class TernaryFalseExpressionToIfRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeAnalyzer\ExprAnalyzer
*/ */
private $exprAnalyzer; private ExprAnalyzer $exprAnalyzer;
public function __construct(ExprAnalyzer $exprAnalyzer) public function __construct(ExprAnalyzer $exprAnalyzer)
{ {
$this->exprAnalyzer = $exprAnalyzer; $this->exprAnalyzer = $exprAnalyzer;

View File

@ -3,6 +3,7 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\CodeQuality\Rector\Foreach_; namespace Rector\CodeQuality\Rector\Foreach_;
use PhpParser\NodeVisitor;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\ArrayDimFetch;
@ -11,7 +12,6 @@ use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt; use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Foreach_; use PhpParser\Node\Stmt\Foreach_;
use PhpParser\NodeTraverser;
use Rector\CodeQuality\NodeAnalyzer\ForeachAnalyzer; use Rector\CodeQuality\NodeAnalyzer\ForeachAnalyzer;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\PhpParser\Node\Value\ValueResolver; use Rector\PhpParser\Node\Value\ValueResolver;
@ -25,14 +25,12 @@ final class ForeachItemsAssignToEmptyArrayToAssignRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\CodeQuality\NodeAnalyzer\ForeachAnalyzer
*/ */
private $foreachAnalyzer; private ForeachAnalyzer $foreachAnalyzer;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(ForeachAnalyzer $foreachAnalyzer, ValueResolver $valueResolver) public function __construct(ForeachAnalyzer $foreachAnalyzer, ValueResolver $valueResolver)
{ {
$this->foreachAnalyzer = $foreachAnalyzer; $this->foreachAnalyzer = $foreachAnalyzer;
@ -116,12 +114,12 @@ CODE_SAMPLE
if ($subNode instanceof Assign && $subNode->var instanceof ArrayDimFetch) { if ($subNode instanceof Assign && $subNode->var instanceof ArrayDimFetch) {
$isAppend = $this->isNames($subNode->var->var, $emptyArrayVariables); $isAppend = $this->isNames($subNode->var->var, $emptyArrayVariables);
if ($isAppend) { if ($isAppend) {
return NodeTraverser::STOP_TRAVERSAL; return NodeVisitor::STOP_TRAVERSAL;
} }
} }
if ($subNode instanceof Assign && $subNode->var instanceof Variable && $this->isNames($subNode->var, $emptyArrayVariables) && !$this->valueResolver->isValue($subNode->expr, [])) { if ($subNode instanceof Assign && $subNode->var instanceof Variable && $this->isNames($subNode->var, $emptyArrayVariables) && !$this->valueResolver->isValue($subNode->expr, [])) {
$isAppend = \true; $isAppend = \true;
return NodeTraverser::STOP_TRAVERSAL; return NodeVisitor::STOP_TRAVERSAL;
} }
return null; return null;
}); });

View File

@ -28,19 +28,16 @@ final class ForeachToInArrayRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeManipulator\BinaryOpManipulator
*/ */
private $binaryOpManipulator; private BinaryOpManipulator $binaryOpManipulator;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
/** /**
* @readonly * @readonly
* @var \PhpParser\NodeFinder
*/ */
private $nodeFinder; private NodeFinder $nodeFinder;
public function __construct(BinaryOpManipulator $binaryOpManipulator, ValueResolver $valueResolver, NodeFinder $nodeFinder) public function __construct(BinaryOpManipulator $binaryOpManipulator, ValueResolver $valueResolver, NodeFinder $nodeFinder)
{ {
$this->binaryOpManipulator = $binaryOpManipulator; $this->binaryOpManipulator = $binaryOpManipulator;
@ -165,9 +162,7 @@ CODE_SAMPLE
*/ */
private function matchNodes($binaryOp, Expr $expr) : ?TwoNodeMatch private function matchNodes($binaryOp, Expr $expr) : ?TwoNodeMatch
{ {
return $this->binaryOpManipulator->matchFirstAndSecondConditionNode($binaryOp, Variable::class, function (Node $node, Node $otherNode) use($expr) : bool { return $this->binaryOpManipulator->matchFirstAndSecondConditionNode($binaryOp, Variable::class, fn(Node $node, Node $otherNode): bool => $this->nodeComparator->areNodesEqual($otherNode, $expr));
return $this->nodeComparator->areNodesEqual($otherNode, $expr);
});
} }
private function isIfBodyABoolReturnNode(If_ $if) : bool private function isIfBodyABoolReturnNode(If_ $if) : bool
{ {

View File

@ -5,8 +5,8 @@ namespace Rector\CodeQuality\Rector\Foreach_;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_; use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\List_;
use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Foreach_; use PhpParser\Node\Stmt\Foreach_;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
@ -23,19 +23,16 @@ final class UnusedForeachValueToArrayKeysRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\DeadCode\NodeAnalyzer\ExprUsedInNodeAnalyzer
*/ */
private $exprUsedInNodeAnalyzer; private ExprUsedInNodeAnalyzer $exprUsedInNodeAnalyzer;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\BetterNodeFinder
*/ */
private $betterNodeFinder; private BetterNodeFinder $betterNodeFinder;
/** /**
* @readonly * @readonly
* @var \Rector\NodeManipulator\StmtsManipulator
*/ */
private $stmtsManipulator; private StmtsManipulator $stmtsManipulator;
public function __construct(ExprUsedInNodeAnalyzer $exprUsedInNodeAnalyzer, BetterNodeFinder $betterNodeFinder, StmtsManipulator $stmtsManipulator) public function __construct(ExprUsedInNodeAnalyzer $exprUsedInNodeAnalyzer, BetterNodeFinder $betterNodeFinder, StmtsManipulator $stmtsManipulator)
{ {
$this->exprUsedInNodeAnalyzer = $exprUsedInNodeAnalyzer; $this->exprUsedInNodeAnalyzer = $exprUsedInNodeAnalyzer;
@ -98,13 +95,14 @@ CODE_SAMPLE
continue; continue;
} }
// special case of nested array items // special case of nested array items
if ($stmt->valueVar instanceof Array_) { if ($stmt->valueVar instanceof List_) {
$valueArray = $this->refactorArrayForeachValue($stmt->valueVar, $stmt); $valueArray = $this->refactorArrayForeachValue($stmt->valueVar, $stmt);
if ($valueArray instanceof Array_) { if (!$valueArray instanceof List_) {
$stmt->valueVar = $valueArray; continue;
} }
$stmt->valueVar = $valueArray;
// not sure what does this mean :) // not sure what does this mean :)
if ($stmt->valueVar->items !== []) { if ($valueArray->items !== []) {
continue; continue;
} }
$hasChanged = \true; $hasChanged = \true;
@ -131,10 +129,10 @@ CODE_SAMPLE
/** /**
* @param int[] $removedKeys * @param int[] $removedKeys
*/ */
private function isArrayItemsRemovalWithoutChangingOrder(Array_ $array, array $removedKeys) : bool private function isArrayItemsRemovalWithoutChangingOrder(List_ $list, array $removedKeys) : bool
{ {
$hasRemovingStarted = \false; $hasRemovingStarted = \false;
foreach (\array_keys($array->items) as $key) { foreach (\array_keys($list->items) as $key) {
if (\in_array($key, $removedKeys, \true)) { if (\in_array($key, $removedKeys, \true)) {
$hasRemovingStarted = \true; $hasRemovingStarted = \true;
} elseif ($hasRemovingStarted) { } elseif ($hasRemovingStarted) {
@ -144,11 +142,11 @@ CODE_SAMPLE
} }
return \true; return \true;
} }
private function refactorArrayForeachValue(Array_ $array, Foreach_ $foreach) : ?Array_ private function refactorArrayForeachValue(List_ $list, Foreach_ $foreach) : ?List_
{ {
// only last items can be removed, without changing the order // only last items can be removed, without changing the order
$removedKeys = []; $removedKeys = [];
foreach ($array->items as $key => $arrayItem) { foreach ($list->items as $key => $arrayItem) {
if (!$arrayItem instanceof ArrayItem) { if (!$arrayItem instanceof ArrayItem) {
// only known values can be processes // only known values can be processes
return null; return null;
@ -163,20 +161,18 @@ CODE_SAMPLE
} }
$removedKeys[] = $key; $removedKeys[] = $key;
} }
if (!$this->isArrayItemsRemovalWithoutChangingOrder($array, $removedKeys)) { if (!$this->isArrayItemsRemovalWithoutChangingOrder($list, $removedKeys)) {
return null; return null;
} }
// clear removed items // clear removed items
foreach ($removedKeys as $removedKey) { foreach ($removedKeys as $removedKey) {
unset($array->items[$removedKey]); unset($list->items[$removedKey]);
} }
return $array; return $list;
} }
private function isVariableUsedInForeach(Variable $variable, Foreach_ $foreach) : bool private function isVariableUsedInForeach(Variable $variable, Foreach_ $foreach) : bool
{ {
return (bool) $this->betterNodeFinder->findFirst($foreach->stmts, function (Node $node) use($variable) : bool { return (bool) $this->betterNodeFinder->findFirst($foreach->stmts, fn(Node $node): bool => $this->exprUsedInNodeAnalyzer->isUsed($node, $variable));
return $this->exprUsedInNodeAnalyzer->isUsed($node, $variable);
});
} }
private function removeForeachValueAndUseArrayKeys(Foreach_ $foreach, Expr $keyVarExpr) : void private function removeForeachValueAndUseArrayKeys(Foreach_ $foreach, Expr $keyVarExpr) : void
{ {

View File

@ -6,7 +6,7 @@ namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Arg; use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\FuncCall;
use Rector\Rector\AbstractRector; use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;

View File

@ -19,9 +19,8 @@ final class CallUserFuncWithArrowFunctionToInlineRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\Php74\NodeAnalyzer\ClosureArrowFunctionAnalyzer
*/ */
private $closureArrowFunctionAnalyzer; private ClosureArrowFunctionAnalyzer $closureArrowFunctionAnalyzer;
public function __construct(ClosureArrowFunctionAnalyzer $closureArrowFunctionAnalyzer) public function __construct(ClosureArrowFunctionAnalyzer $closureArrowFunctionAnalyzer)
{ {
$this->closureArrowFunctionAnalyzer = $closureArrowFunctionAnalyzer; $this->closureArrowFunctionAnalyzer = $closureArrowFunctionAnalyzer;

View File

@ -5,7 +5,7 @@ namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_; use PhpParser\Node\Scalar\String_;
@ -23,9 +23,8 @@ final class CompactToVariablesRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\CodeQuality\CompactConverter
*/ */
private $compactConverter; private CompactConverter $compactConverter;
public function __construct(CompactConverter $compactConverter) public function __construct(CompactConverter $compactConverter)
{ {
$this->compactConverter = $compactConverter; $this->compactConverter = $compactConverter;

View File

@ -3,10 +3,11 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\CodeQuality\Rector\FuncCall; namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\NodeVisitor;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Arg; use PhpParser\Node\Arg;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Cast; use PhpParser\Node\Expr\Cast;
use PhpParser\Node\Expr\Cast\Array_; use PhpParser\Node\Expr\Cast\Array_;
@ -17,7 +18,6 @@ use PhpParser\Node\Expr\Cast\Object_;
use PhpParser\Node\Expr\Cast\String_; use PhpParser\Node\Expr\Cast\String_;
use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Expression;
use PhpParser\NodeTraverser;
use Rector\PhpParser\Node\Value\ValueResolver; use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\Rector\AbstractRector; use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@ -29,9 +29,8 @@ final class SetTypeToCastRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
/** /**
* @var array<string, class-string<Cast>> * @var array<string, class-string<Cast>>
*/ */
@ -78,7 +77,7 @@ CODE_SAMPLE
return [FuncCall::class, Expression::class, Assign::class, ArrayItem::class, Arg::class]; return [FuncCall::class, Expression::class, Assign::class, ArrayItem::class, Arg::class];
} }
/** /**
* @param FuncCall|Expression|Assign|Expr\ArrayItem|Node\Arg $node * @param FuncCall|Expression|Assign|ArrayItem|Node\Arg $node
* @return null|int|\PhpParser\Node\Stmt\Expression|\PhpParser\Node\Expr\Assign|\PhpParser\Node\Expr\Cast * @return null|int|\PhpParser\Node\Stmt\Expression|\PhpParser\Node\Expr\Assign|\PhpParser\Node\Expr\Cast
*/ */
public function refactor(Node $node) public function refactor(Node $node)
@ -93,7 +92,7 @@ CODE_SAMPLE
if (!$this->isSetTypeFuncCall($node->expr)) { if (!$this->isSetTypeFuncCall($node->expr)) {
return null; return null;
} }
return NodeTraverser::DONT_TRAVERSE_CHILDREN; return NodeVisitor::DONT_TRAVERSE_CHILDREN;
} }
if ($node instanceof Expression) { if ($node instanceof Expression) {
if (!$node->expr instanceof FuncCall) { if (!$node->expr instanceof FuncCall) {

View File

@ -17,9 +17,8 @@ final class SimplifyRegexPatternRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeNameResolver\Regex\RegexPatternDetector
*/ */
private $regexPatternDetector; private RegexPatternDetector $regexPatternDetector;
/** /**
* @var array<string, string> * @var array<string, string>
*/ */

View File

@ -6,7 +6,7 @@ namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Arg; use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr\BinaryOp\Equal; use PhpParser\Node\Expr\BinaryOp\Equal;
use PhpParser\Node\Expr\BinaryOp\Identical; use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotEqual; use PhpParser\Node\Expr\BinaryOp\NotEqual;

View File

@ -29,33 +29,26 @@ final class SimplifyUselessVariableRector extends AbstractRector implements Conf
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\AssignAndBinaryMap
*/ */
private $assignAndBinaryMap; private AssignAndBinaryMap $assignAndBinaryMap;
/** /**
* @readonly * @readonly
* @var \Rector\NodeAnalyzer\VariableAnalyzer
*/ */
private $variableAnalyzer; private VariableAnalyzer $variableAnalyzer;
/** /**
* @readonly * @readonly
* @var \Rector\NodeAnalyzer\CallAnalyzer
*/ */
private $callAnalyzer; private CallAnalyzer $callAnalyzer;
/** /**
* @readonly * @readonly
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
*/ */
private $phpDocInfoFactory; private PhpDocInfoFactory $phpDocInfoFactory;
/** /**
* @api * @api
* @var string * @var string
*/ */
public const ONLY_DIRECT_ASSIGN = 'only_direct_assign'; public const ONLY_DIRECT_ASSIGN = 'only_direct_assign';
/** private bool $onlyDirectAssign = \false;
* @var bool
*/
private $onlyDirectAssign = \false;
public function __construct(AssignAndBinaryMap $assignAndBinaryMap, VariableAnalyzer $variableAnalyzer, CallAnalyzer $callAnalyzer, PhpDocInfoFactory $phpDocInfoFactory) public function __construct(AssignAndBinaryMap $assignAndBinaryMap, VariableAnalyzer $variableAnalyzer, CallAnalyzer $callAnalyzer, PhpDocInfoFactory $phpDocInfoFactory)
{ {
$this->assignAndBinaryMap = $assignAndBinaryMap; $this->assignAndBinaryMap = $assignAndBinaryMap;

View File

@ -24,14 +24,12 @@ final class FlipTypeControlToUseExclusiveTypeRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\TypeDeclaration\TypeAnalyzer\NullableTypeAnalyzer
*/ */
private $nullableTypeAnalyzer; private NullableTypeAnalyzer $nullableTypeAnalyzer;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(NullableTypeAnalyzer $nullableTypeAnalyzer, ValueResolver $valueResolver) public function __construct(NullableTypeAnalyzer $nullableTypeAnalyzer, ValueResolver $valueResolver)
{ {
$this->nullableTypeAnalyzer = $nullableTypeAnalyzer; $this->nullableTypeAnalyzer = $nullableTypeAnalyzer;

View File

@ -22,14 +22,12 @@ final class SimplifyArraySearchRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeManipulator\BinaryOpManipulator
*/ */
private $binaryOpManipulator; private BinaryOpManipulator $binaryOpManipulator;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(BinaryOpManipulator $binaryOpManipulator, ValueResolver $valueResolver) public function __construct(BinaryOpManipulator $binaryOpManipulator, ValueResolver $valueResolver)
{ {
$this->binaryOpManipulator = $binaryOpManipulator; $this->binaryOpManipulator = $binaryOpManipulator;
@ -56,9 +54,7 @@ final class SimplifyArraySearchRector extends AbstractRector
return \false; return \false;
} }
return $this->nodeNameResolver->isName($node, 'array_search'); return $this->nodeNameResolver->isName($node, 'array_search');
}, function (Node $node) : bool { }, fn(Node $node): bool => $node instanceof Expr && $this->valueResolver->isFalse($node));
return $node instanceof Expr && $this->valueResolver->isFalse($node);
});
if (!$twoNodeMatch instanceof TwoNodeMatch) { if (!$twoNodeMatch instanceof TwoNodeMatch) {
return null; return null;
} }

View File

@ -19,9 +19,8 @@ final class SimplifyBoolIdenticalTrueRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(ValueResolver $valueResolver) public function __construct(ValueResolver $valueResolver)
{ {
$this->valueResolver = $valueResolver; $this->valueResolver = $valueResolver;

View File

@ -24,19 +24,16 @@ final class SimplifyConditionsRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\AssignAndBinaryMap
*/ */
private $assignAndBinaryMap; private AssignAndBinaryMap $assignAndBinaryMap;
/** /**
* @readonly * @readonly
* @var \Rector\NodeManipulator\BinaryOpManipulator
*/ */
private $binaryOpManipulator; private BinaryOpManipulator $binaryOpManipulator;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(AssignAndBinaryMap $assignAndBinaryMap, BinaryOpManipulator $binaryOpManipulator, ValueResolver $valueResolver) public function __construct(AssignAndBinaryMap $assignAndBinaryMap, BinaryOpManipulator $binaryOpManipulator, ValueResolver $valueResolver)
{ {
$this->assignAndBinaryMap = $assignAndBinaryMap; $this->assignAndBinaryMap = $assignAndBinaryMap;
@ -76,11 +73,7 @@ final class SimplifyConditionsRector extends AbstractRector
} }
private function processIdenticalAndNotIdentical(Identical $identical) : ?Node private function processIdenticalAndNotIdentical(Identical $identical) : ?Node
{ {
$twoNodeMatch = $this->binaryOpManipulator->matchFirstAndSecondConditionNode($identical, static function (Node $node) : bool { $twoNodeMatch = $this->binaryOpManipulator->matchFirstAndSecondConditionNode($identical, static fn(Node $node): bool => $node instanceof Identical || $node instanceof NotIdentical, fn(Node $node): bool => $node instanceof Expr && $this->valueResolver->isTrueOrFalse($node));
return $node instanceof Identical || $node instanceof NotIdentical;
}, function (Node $node) : bool {
return $node instanceof Expr && $this->valueResolver->isTrueOrFalse($node);
});
if (!$twoNodeMatch instanceof TwoNodeMatch) { if (!$twoNodeMatch instanceof TwoNodeMatch) {
return $twoNodeMatch; return $twoNodeMatch;
} }

View File

@ -19,9 +19,8 @@ final class StrlenZeroToIdenticalEmptyStringRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(ValueResolver $valueResolver) public function __construct(ValueResolver $valueResolver)
{ {
$this->valueResolver = $valueResolver; $this->valueResolver = $valueResolver;

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodeQuality\Rector\If_; namespace Rector\CodeQuality\Rector\If_;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\BinaryOp\BooleanAnd; use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
use PhpParser\Node\Stmt\Else_; use PhpParser\Node\Stmt\Else_;
use PhpParser\Node\Stmt\If_; use PhpParser\Node\Stmt\If_;
@ -22,14 +23,12 @@ final class CombineIfRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\BetterPhpDocParser\Comment\CommentsMerger
*/ */
private $commentsMerger; private CommentsMerger $commentsMerger;
/** /**
* @readonly * @readonly
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
*/ */
private $phpDocInfoFactory; private PhpDocInfoFactory $phpDocInfoFactory;
public function __construct(CommentsMerger $commentsMerger, PhpDocInfoFactory $phpDocInfoFactory) public function __construct(CommentsMerger $commentsMerger, PhpDocInfoFactory $phpDocInfoFactory)
{ {
$this->commentsMerger = $commentsMerger; $this->commentsMerger = $commentsMerger;
@ -84,6 +83,13 @@ CODE_SAMPLE
return null; return null;
} }
$node->cond->setAttribute(AttributeKey::ORIGINAL_NODE, null); $node->cond->setAttribute(AttributeKey::ORIGINAL_NODE, null);
$cond = $node->cond;
while ($cond instanceof BinaryOp) {
if (!$cond->right instanceof BinaryOp) {
$cond->right->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
$cond = $cond->right;
}
$node->cond = new BooleanAnd($node->cond, $subIf->cond); $node->cond = new BooleanAnd($node->cond, $subIf->cond);
$node->stmts = $subIf->stmts; $node->stmts = $subIf->stmts;
$this->commentsMerger->keepComments($node, [$subIf]); $this->commentsMerger->keepComments($node, [$subIf]);

View File

@ -82,7 +82,7 @@ CODE_SAMPLE
if ($i === $condEndTokenPos) { if ($i === $condEndTokenPos) {
return \false; return \false;
} }
if (\in_array($oldTokens[$i], ['{', ':'], \true)) { if (\in_array((string) $oldTokens[$i], ['{', ':'], \true)) {
// all good // all good
return \true; return \true;
} }

View File

@ -6,11 +6,11 @@ namespace Rector\CodeQuality\Rector\If_;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Coalesce; use PhpParser\Node\Expr\BinaryOp\Coalesce;
use PhpParser\Node\Expr\Throw_ as ExprThrow_;
use PhpParser\Node\Stmt; use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\If_; use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_; use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\Stmt\Throw_; use PhpParser\Node\Expr\Throw_;
use PhpParser\Node\Stmt\Expression;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\NodeManipulator\IfManipulator; use Rector\NodeManipulator\IfManipulator;
use Rector\PhpParser\Node\Value\ValueResolver; use Rector\PhpParser\Node\Value\ValueResolver;
@ -26,14 +26,12 @@ final class ConsecutiveNullCompareReturnsToNullCoalesceQueueRector extends Abstr
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeManipulator\IfManipulator
*/ */
private $ifManipulator; private IfManipulator $ifManipulator;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(IfManipulator $ifManipulator, ValueResolver $valueResolver) public function __construct(IfManipulator $ifManipulator, ValueResolver $valueResolver)
{ {
$this->ifManipulator = $ifManipulator; $this->ifManipulator = $ifManipulator;
@ -117,9 +115,9 @@ CODE_SAMPLE
if (!$hasChanged) { if (!$hasChanged) {
continue; continue;
} }
if ($stmt instanceof Throw_) { if ($stmt instanceof Expression && $stmt->expr instanceof Throw_) {
unset($node->stmts[$key]); unset($node->stmts[$key]);
$appendExpr = new ExprThrow_($stmt->expr); $appendExpr = $stmt->expr;
continue; continue;
} }
if (!$this->isReturnNull($stmt)) { if (!$this->isReturnNull($stmt)) {

View File

@ -3,6 +3,8 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\CodeQuality\Rector\If_; namespace Rector\CodeQuality\Rector\If_;
use PhpParser\Node\Scalar\Int_;
use PhpParser\Node\Scalar\Float_;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\Array_;
@ -18,8 +20,6 @@ use PhpParser\Node\Expr\Cast\Bool_;
use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Ternary; use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\DNumber;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\String_; use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt; use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ElseIf_; use PhpParser\Node\Stmt\ElseIf_;
@ -40,19 +40,16 @@ final class ExplicitBoolCompareRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeTypeResolver\TypeAnalyzer\StringTypeAnalyzer
*/ */
private $stringTypeAnalyzer; private StringTypeAnalyzer $stringTypeAnalyzer;
/** /**
* @readonly * @readonly
* @var \Rector\NodeTypeResolver\TypeAnalyzer\ArrayTypeAnalyzer
*/ */
private $arrayTypeAnalyzer; private ArrayTypeAnalyzer $arrayTypeAnalyzer;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(StringTypeAnalyzer $stringTypeAnalyzer, ArrayTypeAnalyzer $arrayTypeAnalyzer, ValueResolver $valueResolver) public function __construct(StringTypeAnalyzer $stringTypeAnalyzer, ArrayTypeAnalyzer $arrayTypeAnalyzer, ValueResolver $valueResolver)
{ {
$this->stringTypeAnalyzer = $stringTypeAnalyzer; $this->stringTypeAnalyzer = $stringTypeAnalyzer;
@ -165,12 +162,12 @@ CODE_SAMPLE
if ($countedType->isArray()->yes()) { if ($countedType->isArray()->yes()) {
return null; return null;
} }
$lNumber = new LNumber(0); $int = new Int_(0);
// compare === 0, assumption // compare === 0, assumption
if ($isNegated) { if ($isNegated) {
return new Identical($funcCall, $lNumber); return new Identical($funcCall, $int);
} }
return new Greater($funcCall, $lNumber); return new Greater($funcCall, $int);
} }
/** /**
* @return Identical|NotIdentical|null * @return Identical|NotIdentical|null
@ -234,22 +231,22 @@ CODE_SAMPLE
*/ */
private function resolveInteger(bool $isNegated, Expr $expr) private function resolveInteger(bool $isNegated, Expr $expr)
{ {
$lNumber = new LNumber(0); $int = new Int_(0);
if ($isNegated) { if ($isNegated) {
return new Identical($expr, $lNumber); return new Identical($expr, $int);
} }
return new NotIdentical($expr, $lNumber); return new NotIdentical($expr, $int);
} }
/** /**
* @return \PhpParser\Node\Expr\BinaryOp\Identical|\PhpParser\Node\Expr\BinaryOp\NotIdentical * @return \PhpParser\Node\Expr\BinaryOp\Identical|\PhpParser\Node\Expr\BinaryOp\NotIdentical
*/ */
private function resolveFloat(bool $isNegated, Expr $expr) private function resolveFloat(bool $isNegated, Expr $expr)
{ {
$dNumber = new DNumber(0.0); $float = new Float_(0.0);
if ($isNegated) { if ($isNegated) {
return new Identical($expr, $dNumber); return new Identical($expr, $float);
} }
return new NotIdentical($expr, $dNumber); return new NotIdentical($expr, $float);
} }
/** /**
* @return \PhpParser\Node\Expr\BinaryOp\Identical|\PhpParser\Node\Expr\BinaryOp\NotIdentical * @return \PhpParser\Node\Expr\BinaryOp\Identical|\PhpParser\Node\Expr\BinaryOp\NotIdentical

View File

@ -23,14 +23,12 @@ final class SimplifyIfElseToTernaryRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Printer\BetterStandardPrinter
*/ */
private $betterStandardPrinter; private BetterStandardPrinter $betterStandardPrinter;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\BetterNodeFinder
*/ */
private $betterNodeFinder; private BetterNodeFinder $betterNodeFinder;
/** /**
* @var int * @var int
*/ */

View File

@ -21,14 +21,12 @@ final class SimplifyIfNotNullReturnRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeManipulator\IfManipulator
*/ */
private $ifManipulator; private IfManipulator $ifManipulator;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(IfManipulator $ifManipulator, ValueResolver $valueResolver) public function __construct(IfManipulator $ifManipulator, ValueResolver $valueResolver)
{ {
$this->ifManipulator = $ifManipulator; $this->ifManipulator = $ifManipulator;

View File

@ -32,24 +32,20 @@ final class SimplifyIfNullableReturnRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeManipulator\IfManipulator
*/ */
private $ifManipulator; private IfManipulator $ifManipulator;
/** /**
* @readonly * @readonly
* @var \Rector\CodeQuality\TypeResolver\AssignVariableTypeResolver
*/ */
private $assignVariableTypeResolver; private AssignVariableTypeResolver $assignVariableTypeResolver;
/** /**
* @readonly * @readonly
* @var \Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover
*/ */
private $varTagRemover; private VarTagRemover $varTagRemover;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(IfManipulator $ifManipulator, AssignVariableTypeResolver $assignVariableTypeResolver, VarTagRemover $varTagRemover, ValueResolver $valueResolver) public function __construct(IfManipulator $ifManipulator, AssignVariableTypeResolver $assignVariableTypeResolver, VarTagRemover $varTagRemover, ValueResolver $valueResolver)
{ {
$this->ifManipulator = $ifManipulator; $this->ifManipulator = $ifManipulator;

View File

@ -16,6 +16,7 @@ use PhpParser\Node\Stmt\Return_;
use Rector\BetterPhpDocParser\Comment\CommentsMerger; use Rector\BetterPhpDocParser\Comment\CommentsMerger;
use Rector\CodeQuality\NodeManipulator\ExprBoolCaster; use Rector\CodeQuality\NodeManipulator\ExprBoolCaster;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpParser\Node\Value\ValueResolver; use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\PhpParser\Printer\BetterStandardPrinter; use Rector\PhpParser\Printer\BetterStandardPrinter;
use Rector\Rector\AbstractRector; use Rector\Rector\AbstractRector;
@ -28,24 +29,20 @@ final class SimplifyIfReturnBoolRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\BetterPhpDocParser\Comment\CommentsMerger
*/ */
private $commentsMerger; private CommentsMerger $commentsMerger;
/** /**
* @readonly * @readonly
* @var \Rector\CodeQuality\NodeManipulator\ExprBoolCaster
*/ */
private $exprBoolCaster; private ExprBoolCaster $exprBoolCaster;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Printer\BetterStandardPrinter
*/ */
private $betterStandardPrinter; private BetterStandardPrinter $betterStandardPrinter;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(CommentsMerger $commentsMerger, ExprBoolCaster $exprBoolCaster, BetterStandardPrinter $betterStandardPrinter, ValueResolver $valueResolver) public function __construct(CommentsMerger $commentsMerger, ExprBoolCaster $exprBoolCaster, BetterStandardPrinter $betterStandardPrinter, ValueResolver $valueResolver)
{ {
$this->commentsMerger = $commentsMerger; $this->commentsMerger = $commentsMerger;
@ -101,6 +98,7 @@ CODE_SAMPLE
if (!$innerIfInnerNode instanceof Expr) { if (!$innerIfInnerNode instanceof Expr) {
continue; continue;
} }
$if->cond->setAttribute(AttributeKey::ORIGINAL_NODE, null);
$newReturn = $this->resolveReturn($innerIfInnerNode, $if, $return); $newReturn = $this->resolveReturn($innerIfInnerNode, $if, $return);
if (!$newReturn instanceof Return_) { if (!$newReturn instanceof Return_) {
continue; continue;

View File

@ -20,9 +20,8 @@ final class AbsolutizeRequireAndIncludePathRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(ValueResolver $valueResolver) public function __construct(ValueResolver $valueResolver)
{ {
$this->valueResolver = $valueResolver; $this->valueResolver = $valueResolver;

View File

@ -33,19 +33,16 @@ final class IssetOnPropertyObjectToPropertyExistsRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \PHPStan\Reflection\ReflectionProvider
*/ */
private $reflectionProvider; private ReflectionProvider $reflectionProvider;
/** /**
* @readonly * @readonly
* @var \Rector\Reflection\ReflectionResolver
*/ */
private $reflectionResolver; private ReflectionResolver $reflectionResolver;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(ReflectionProvider $reflectionProvider, ReflectionResolver $reflectionResolver, ValueResolver $valueResolver) public function __construct(ReflectionProvider $reflectionProvider, ReflectionResolver $reflectionResolver, ValueResolver $valueResolver)
{ {
$this->reflectionProvider = $reflectionProvider; $this->reflectionProvider = $reflectionProvider;

View File

@ -39,8 +39,9 @@ CODE_SAMPLE
} }
/** /**
* @param LogicalOr|LogicalAnd $node * @param LogicalOr|LogicalAnd $node
* @return \PhpParser\Node\Expr\BinaryOp\BooleanAnd|\PhpParser\Node\Expr\BinaryOp\BooleanOr
*/ */
public function refactor(Node $node) : ?Node public function refactor(Node $node)
{ {
return $this->refactorLogicalToBoolean($node); return $this->refactorLogicalToBoolean($node);
} }

View File

@ -61,10 +61,7 @@ CODE_SAMPLE
$tokenEndPos = $notEqual->getEndTokenPos(); $tokenEndPos = $notEqual->getEndTokenPos();
for ($i = $tokenStartPos; $i < $tokenEndPos; ++$i) { for ($i = $tokenStartPos; $i < $tokenEndPos; ++$i) {
$token = $this->file->getOldTokens()[$i]; $token = $this->file->getOldTokens()[$i];
if (!isset($token[1])) { if ((string) $token === '<>') {
continue;
}
if ($token[1] === '<>') {
return \true; return \true;
} }
} }

View File

@ -25,9 +25,8 @@ final class CleanupUnneededNullsafeOperatorRector extends AbstractRector impleme
{ {
/** /**
* @readonly * @readonly
* @var \Rector\TypeDeclaration\TypeAnalyzer\ReturnStrictTypeAnalyzer
*/ */
private $returnStrictTypeAnalyzer; private ReturnStrictTypeAnalyzer $returnStrictTypeAnalyzer;
public function __construct(ReturnStrictTypeAnalyzer $returnStrictTypeAnalyzer) public function __construct(ReturnStrictTypeAnalyzer $returnStrictTypeAnalyzer)
{ {
$this->returnStrictTypeAnalyzer = $returnStrictTypeAnalyzer; $this->returnStrictTypeAnalyzer = $returnStrictTypeAnalyzer;

View File

@ -21,9 +21,8 @@ final class SingularSwitchToIfRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\Renaming\NodeManipulator\SwitchManipulator
*/ */
private $switchManipulator; private SwitchManipulator $switchManipulator;
public function __construct(SwitchManipulator $switchManipulator) public function __construct(SwitchManipulator $switchManipulator)
{ {
$this->switchManipulator = $switchManipulator; $this->switchManipulator = $switchManipulator;
@ -81,9 +80,7 @@ CODE_SAMPLE
// only default → basically unwrap // only default → basically unwrap
if (!$onlyCase->cond instanceof Expr) { if (!$onlyCase->cond instanceof Expr) {
// remove default clause because it cause syntax error // remove default clause because it cause syntax error
return \array_filter($onlyCase->stmts, static function (Stmt $stmt) : bool { return \array_filter($onlyCase->stmts, static fn(Stmt $stmt): bool => !$stmt instanceof Break_);
return !$stmt instanceof Break_;
});
} }
$if = new If_(new Identical($node->cond, $onlyCase->cond)); $if = new If_(new Identical($node->cond, $onlyCase->cond));
$if->stmts = $this->switchManipulator->removeBreakNodes($onlyCase->stmts); $if->stmts = $this->switchManipulator->removeBreakNodes($onlyCase->stmts);

View File

@ -21,9 +21,8 @@ final class SwitchTrueToIfRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(ValueResolver $valueResolver) public function __construct(ValueResolver $valueResolver)
{ {
$this->valueResolver = $valueResolver; $this->valueResolver = $valueResolver;

View File

@ -20,9 +20,8 @@ final class ArrayKeyExistsTernaryThenValueToCoalescingRector extends AbstractRec
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(ValueResolver $valueResolver) public function __construct(ValueResolver $valueResolver)
{ {
$this->valueResolver = $valueResolver; $this->valueResolver = $valueResolver;

View File

@ -19,9 +19,8 @@ final class SimplifyTautologyTernaryRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeManipulator\BinaryOpManipulator
*/ */
private $binaryOpManipulator; private BinaryOpManipulator $binaryOpManipulator;
public function __construct(BinaryOpManipulator $binaryOpManipulator) public function __construct(BinaryOpManipulator $binaryOpManipulator)
{ {
$this->binaryOpManipulator = $binaryOpManipulator; $this->binaryOpManipulator = $binaryOpManipulator;
@ -45,11 +44,7 @@ final class SimplifyTautologyTernaryRector extends AbstractRector
if (!$node->cond instanceof NotIdentical && !$node->cond instanceof Identical) { if (!$node->cond instanceof NotIdentical && !$node->cond instanceof Identical) {
return null; return null;
} }
$twoNodeMatch = $this->binaryOpManipulator->matchFirstAndSecondConditionNode($node->cond, function (Node $leftNode) use($node) : bool { $twoNodeMatch = $this->binaryOpManipulator->matchFirstAndSecondConditionNode($node->cond, fn(Node $leftNode): bool => $this->nodeComparator->areNodesEqual($leftNode, $node->if), fn(Node $leftNode): bool => $this->nodeComparator->areNodesEqual($leftNode, $node->else));
return $this->nodeComparator->areNodesEqual($leftNode, $node->if);
}, function (Node $leftNode) use($node) : bool {
return $this->nodeComparator->areNodesEqual($leftNode, $node->else);
});
if (!$twoNodeMatch instanceof TwoNodeMatch) { if (!$twoNodeMatch instanceof TwoNodeMatch) {
return null; return null;
} }

View File

@ -61,12 +61,19 @@ CODE_SAMPLE
return null; return null;
} }
$node->cond = $node->cond->expr; $node->cond = $node->cond->expr;
[$node->if, $node->else] = [$node->else, $node->if]; $else = clone $node->else;
$if = clone $node->if;
$node->else = $if;
$node->if = $else;
if ($node->if instanceof Ternary) { if ($node->if instanceof Ternary) {
$ternary = $node->if; $ternary = $node->if;
$ternary->setAttribute(AttributeKey::KIND, 'wrapped_with_brackets'); $ternary->setAttribute(AttributeKey::KIND, 'wrapped_with_brackets');
$ternary->setAttribute(AttributeKey::ORIGINAL_NODE, null); $ternary->setAttribute(AttributeKey::ORIGINAL_NODE, null);
} }
if ($node->else instanceof Ternary) {
$ternary = $node->else;
$ternary->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
return $node; return $node;
} }
} }

View File

@ -21,14 +21,12 @@ final class UnnecessaryTernaryExpressionRector extends AbstractRector
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\AssignAndBinaryMap
*/ */
private $assignAndBinaryMap; private AssignAndBinaryMap $assignAndBinaryMap;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/ */
private $valueResolver; private ValueResolver $valueResolver;
public function __construct(AssignAndBinaryMap $assignAndBinaryMap, ValueResolver $valueResolver) public function __construct(AssignAndBinaryMap $assignAndBinaryMap, ValueResolver $valueResolver)
{ {
$this->assignAndBinaryMap = $assignAndBinaryMap; $this->assignAndBinaryMap = $assignAndBinaryMap;

View File

@ -14,9 +14,8 @@ final class ArrayDimFetchTypeResolver
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeTypeResolver\NodeTypeResolver
*/ */
private $nodeTypeResolver; private NodeTypeResolver $nodeTypeResolver;
public function __construct(NodeTypeResolver $nodeTypeResolver) public function __construct(NodeTypeResolver $nodeTypeResolver)
{ {
$this->nodeTypeResolver = $nodeTypeResolver; $this->nodeTypeResolver = $nodeTypeResolver;

View File

@ -11,9 +11,8 @@ final class AssignVariableTypeResolver
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeTypeResolver\NodeTypeResolver
*/ */
private $nodeTypeResolver; private NodeTypeResolver $nodeTypeResolver;
public function __construct(NodeTypeResolver $nodeTypeResolver) public function __construct(NodeTypeResolver $nodeTypeResolver)
{ {
$this->nodeTypeResolver = $nodeTypeResolver; $this->nodeTypeResolver = $nodeTypeResolver;

View File

@ -9,19 +9,17 @@ final class KeyAndExpr
{ {
/** /**
* @readonly * @readonly
* @var \PhpParser\Node\Expr|null
*/ */
private $keyExpr; private ?Expr $keyExpr;
/** /**
* @readonly * @readonly
* @var \PhpParser\Node\Expr
*/ */
private $expr; private Expr $expr;
/** /**
* @var Comment[] * @var Comment[]
* @readonly * @readonly
*/ */
private $comments; private array $comments;
/** /**
* @param Comment[] $comments * @param Comment[] $comments
*/ */

View File

@ -22,14 +22,12 @@ final class UseImportsAdder
{ {
/** /**
* @readonly * @readonly
* @var \Rector\CodingStyle\ClassNameImport\UsedImportsResolver
*/ */
private $usedImportsResolver; private UsedImportsResolver $usedImportsResolver;
/** /**
* @readonly * @readonly
* @var \Rector\NodeTypeResolver\PHPStan\Type\TypeFactory
*/ */
private $typeFactory; private TypeFactory $typeFactory;
public function __construct(UsedImportsResolver $usedImportsResolver, TypeFactory $typeFactory) public function __construct(UsedImportsResolver $usedImportsResolver, TypeFactory $typeFactory)
{ {
$this->usedImportsResolver = $usedImportsResolver; $this->usedImportsResolver = $usedImportsResolver;

View File

@ -10,9 +10,8 @@ final class UseImportsRemover
{ {
/** /**
* @readonly * @readonly
* @var \Rector\Renaming\Collector\RenamedNameCollector
*/ */
private $renamedNameCollector; private RenamedNameCollector $renamedNameCollector;
public function __construct(RenamedNameCollector $renamedNameCollector) public function __construct(RenamedNameCollector $renamedNameCollector)
{ {
$this->renamedNameCollector = $renamedNameCollector; $this->renamedNameCollector = $renamedNameCollector;

View File

@ -3,20 +3,19 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\CodingStyle\ClassNameImport; namespace Rector\CodingStyle\ClassNameImport;
use PhpParser\Node\UseItem;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Identifier; use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt; use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Namespace_; use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\Use_; use PhpParser\Node\Stmt\Use_;
use PhpParser\Node\Stmt\UseUse;
use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace; use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace;
final class AliasUsesResolver final class AliasUsesResolver
{ {
/** /**
* @readonly * @readonly
* @var \Rector\CodingStyle\ClassNameImport\UseImportsTraverser
*/ */
private $useImportsTraverser; private \Rector\CodingStyle\ClassNameImport\UseImportsTraverser $useImportsTraverser;
public function __construct(\Rector\CodingStyle\ClassNameImport\UseImportsTraverser $useImportsTraverser) public function __construct(\Rector\CodingStyle\ClassNameImport\UseImportsTraverser $useImportsTraverser)
{ {
$this->useImportsTraverser = $useImportsTraverser; $this->useImportsTraverser = $useImportsTraverser;
@ -29,9 +28,7 @@ final class AliasUsesResolver
{ {
if (!$node instanceof Namespace_ && !$node instanceof FileWithoutNamespace) { if (!$node instanceof Namespace_ && !$node instanceof FileWithoutNamespace) {
/** @var Namespace_[]|FileWithoutNamespace[] $namespaces */ /** @var Namespace_[]|FileWithoutNamespace[] $namespaces */
$namespaces = \array_filter($stmts, static function (Stmt $stmt) : bool { $namespaces = \array_filter($stmts, static fn(Stmt $stmt): bool => $stmt instanceof Namespace_ || $stmt instanceof FileWithoutNamespace);
return $stmt instanceof Namespace_ || $stmt instanceof FileWithoutNamespace;
});
if (\count($namespaces) !== 1) { if (\count($namespaces) !== 1) {
return []; return [];
} }
@ -47,11 +44,11 @@ final class AliasUsesResolver
{ {
$aliasedUses = []; $aliasedUses = [];
/** @param Use_::TYPE_* $useType */ /** @param Use_::TYPE_* $useType */
$this->useImportsTraverser->traverserStmts($stmts, static function (int $useType, UseUse $useUse, string $name) use(&$aliasedUses) : void { $this->useImportsTraverser->traverserStmts($stmts, static function (int $useType, UseItem $useItem, string $name) use(&$aliasedUses) : void {
if ($useType !== Use_::TYPE_NORMAL) { if ($useType !== Use_::TYPE_NORMAL) {
return; return;
} }
if (!$useUse->alias instanceof Identifier) { if (!$useItem->alias instanceof Identifier) {
return; return;
} }
$aliasedUses[] = $name; $aliasedUses[] = $name;

View File

@ -21,9 +21,8 @@ final class AliasClassNameImportSkipVoter implements ClassNameImportSkipVoterInt
{ {
/** /**
* @readonly * @readonly
* @var \Rector\CodingStyle\ClassNameImport\AliasUsesResolver
*/ */
private $aliasUsesResolver; private AliasUsesResolver $aliasUsesResolver;
public function __construct(AliasUsesResolver $aliasUsesResolver) public function __construct(AliasUsesResolver $aliasUsesResolver)
{ {
$this->aliasUsesResolver = $aliasUsesResolver; $this->aliasUsesResolver = $aliasUsesResolver;

View File

@ -21,9 +21,8 @@ final class ClassLikeNameClassNameImportSkipVoter implements ClassNameImportSkip
{ {
/** /**
* @readonly * @readonly
* @var \Rector\CodingStyle\ClassNameImport\ShortNameResolver
*/ */
private $shortNameResolver; private ShortNameResolver $shortNameResolver;
public function __construct(ShortNameResolver $shortNameResolver) public function __construct(ShortNameResolver $shortNameResolver)
{ {
$this->shortNameResolver = $shortNameResolver; $this->shortNameResolver = $shortNameResolver;

View File

@ -22,9 +22,8 @@ final class FullyQualifiedNameClassNameImportSkipVoter implements ClassNameImpor
{ {
/** /**
* @readonly * @readonly
* @var \Rector\CodingStyle\ClassNameImport\ShortNameResolver
*/ */
private $shortNameResolver; private ShortNameResolver $shortNameResolver;
public function __construct(ShortNameResolver $shortNameResolver) public function __construct(ShortNameResolver $shortNameResolver)
{ {
$this->shortNameResolver = $shortNameResolver; $this->shortNameResolver = $shortNameResolver;

View File

@ -19,9 +19,8 @@ final class UsesClassNameImportSkipVoter implements ClassNameImportSkipVoterInte
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PostRector\Collector\UseNodesToAddCollector
*/ */
private $useNodesToAddCollector; private UseNodesToAddCollector $useNodesToAddCollector;
public function __construct(UseNodesToAddCollector $useNodesToAddCollector) public function __construct(UseNodesToAddCollector $useNodesToAddCollector)
{ {
$this->useNodesToAddCollector = $useNodesToAddCollector; $this->useNodesToAddCollector = $useNodesToAddCollector;

View File

@ -3,13 +3,13 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\CodingStyle\ClassNameImport; namespace Rector\CodingStyle\ClassNameImport;
use PhpParser\Node\UseItem;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Identifier; use PhpParser\Node\Identifier;
use PhpParser\Node\Name; use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\GroupUse; use PhpParser\Node\Stmt\GroupUse;
use PhpParser\Node\Stmt\Use_; use PhpParser\Node\Stmt\Use_;
use PhpParser\Node\Stmt\UseUse;
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface; use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
use Rector\Configuration\Option; use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider; use Rector\Configuration\Parameter\SimpleParameterProvider;
@ -23,12 +23,11 @@ final class ClassNameImportSkipper
* @var ClassNameImportSkipVoterInterface[] * @var ClassNameImportSkipVoterInterface[]
* @readonly * @readonly
*/ */
private $classNameImportSkipVoters; private iterable $classNameImportSkipVoters;
/** /**
* @readonly * @readonly
* @var \Rector\Naming\Naming\UseImportsResolver
*/ */
private $useImportsResolver; private UseImportsResolver $useImportsResolver;
/** /**
* @param ClassNameImportSkipVoterInterface[] $classNameImportSkipVoters * @param ClassNameImportSkipVoterInterface[] $classNameImportSkipVoters
*/ */
@ -102,11 +101,11 @@ final class ClassNameImportSkipper
} }
return $fullyQualified->getAttribute(AttributeKey::IS_FUNCCALL_NAME) === \true; return $fullyQualified->getAttribute(AttributeKey::IS_FUNCCALL_NAME) === \true;
} }
private function isConflictedShortNameInUse(UseUse $useUse, string $useName, string $lastUseName, string $stringName) : bool private function isConflictedShortNameInUse(UseItem $useItem, string $useName, string $lastUseName, string $stringName) : bool
{ {
if (!$useUse->alias instanceof Identifier && $useName !== $stringName && $lastUseName === $stringName) { if (!$useItem->alias instanceof Identifier && $useName !== $stringName && $lastUseName === $stringName) {
return \true; return \true;
} }
return $useUse->alias instanceof Identifier && $useUse->alias->toString() === $stringName; return $useItem->alias instanceof Identifier && $useItem->alias->toString() === $stringName;
} }
} }

View File

@ -28,33 +28,28 @@ final class ShortNameResolver
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser
*/ */
private $simpleCallableNodeTraverser; private SimpleCallableNodeTraverser $simpleCallableNodeTraverser;
/** /**
* @readonly * @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/ */
private $nodeNameResolver; private NodeNameResolver $nodeNameResolver;
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\BetterNodeFinder
*/ */
private $betterNodeFinder; private BetterNodeFinder $betterNodeFinder;
/** /**
* @readonly * @readonly
* @var \Rector\CodingStyle\NodeAnalyzer\UseImportNameMatcher
*/ */
private $useImportNameMatcher; private UseImportNameMatcher $useImportNameMatcher;
/** /**
* @readonly * @readonly
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
*/ */
private $phpDocInfoFactory; private PhpDocInfoFactory $phpDocInfoFactory;
/** /**
* @var array<string, string[]> * @var array<string, string[]>
*/ */
private $shortNamesByFilePath = []; private array $shortNamesByFilePath = [];
public function __construct(SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeNameResolver $nodeNameResolver, BetterNodeFinder $betterNodeFinder, UseImportNameMatcher $useImportNameMatcher, PhpDocInfoFactory $phpDocInfoFactory) public function __construct(SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeNameResolver $nodeNameResolver, BetterNodeFinder $betterNodeFinder, UseImportNameMatcher $useImportNameMatcher, PhpDocInfoFactory $phpDocInfoFactory)
{ {
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser; $this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
@ -84,9 +79,7 @@ final class ShortNameResolver
{ {
$newStmts = $file->getNewStmts(); $newStmts = $file->getNewStmts();
/** @var Namespace_[]|FileWithoutNamespace[] $namespaces */ /** @var Namespace_[]|FileWithoutNamespace[] $namespaces */
$namespaces = \array_filter($newStmts, static function (Stmt $stmt) : bool { $namespaces = \array_filter($newStmts, static fn(Stmt $stmt): bool => $stmt instanceof Namespace_ || $stmt instanceof FileWithoutNamespace);
return $stmt instanceof Namespace_ || $stmt instanceof FileWithoutNamespace;
});
if (\count($namespaces) !== 1) { if (\count($namespaces) !== 1) {
// only handle single namespace nodes // only handle single namespace nodes
return []; return [];

View File

@ -3,27 +3,26 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\CodingStyle\ClassNameImport; namespace Rector\CodingStyle\ClassNameImport;
use PhpParser\Node\UseItem;
use PhpParser\Node\Stmt; use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\GroupUse; use PhpParser\Node\Stmt\GroupUse;
use PhpParser\Node\Stmt\Namespace_; use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\Use_; use PhpParser\Node\Stmt\Use_;
use PhpParser\Node\Stmt\UseUse;
use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeNameResolver\NodeNameResolver;
use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace; use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace;
final class UseImportsTraverser final class UseImportsTraverser
{ {
/** /**
* @readonly * @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/ */
private $nodeNameResolver; private NodeNameResolver $nodeNameResolver;
public function __construct(NodeNameResolver $nodeNameResolver) public function __construct(NodeNameResolver $nodeNameResolver)
{ {
$this->nodeNameResolver = $nodeNameResolver; $this->nodeNameResolver = $nodeNameResolver;
} }
/** /**
* @param Stmt[] $stmts * @param Stmt[] $stmts
* @param callable(Use_::TYPE_* $useType, UseUse $useUse, string $name): void $callable * @param callable(Use_::TYPE_* $useType, UseItem $useUse, string $name):void $callable
*/ */
public function traverserStmts(array $stmts, callable $callable) : void public function traverserStmts(array $stmts, callable $callable) : void
{ {
@ -48,7 +47,7 @@ final class UseImportsTraverser
} }
} }
/** /**
* @param callable(Use_::TYPE_* $useType, UseUse $useUse, string $name): void $callable * @param callable(Use_::TYPE_* $useType, UseItem $useUse, string $name):void $callable
*/ */
private function processGroupUse(GroupUse $groupUse, callable $callable) : void private function processGroupUse(GroupUse $groupUse, callable $callable) : void
{ {

View File

@ -3,11 +3,11 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\CodingStyle\ClassNameImport; namespace Rector\CodingStyle\ClassNameImport;
use PhpParser\Node\UseItem;
use PhpParser\Node\Identifier; use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt; use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Use_; use PhpParser\Node\Stmt\Use_;
use PhpParser\Node\Stmt\UseUse;
use Rector\CodingStyle\ClassNameImport\ValueObject\UsedImports; use Rector\CodingStyle\ClassNameImport\ValueObject\UsedImports;
use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeNameResolver\NodeNameResolver;
use Rector\PhpParser\Node\BetterNodeFinder; use Rector\PhpParser\Node\BetterNodeFinder;
@ -17,19 +17,16 @@ final class UsedImportsResolver
{ {
/** /**
* @readonly * @readonly
* @var \Rector\PhpParser\Node\BetterNodeFinder
*/ */
private $betterNodeFinder; private BetterNodeFinder $betterNodeFinder;
/** /**
* @readonly * @readonly
* @var \Rector\CodingStyle\ClassNameImport\UseImportsTraverser
*/ */
private $useImportsTraverser; private \Rector\CodingStyle\ClassNameImport\UseImportsTraverser $useImportsTraverser;
/** /**
* @readonly * @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/ */
private $nodeNameResolver; private NodeNameResolver $nodeNameResolver;
public function __construct(BetterNodeFinder $betterNodeFinder, \Rector\CodingStyle\ClassNameImport\UseImportsTraverser $useImportsTraverser, NodeNameResolver $nodeNameResolver) public function __construct(BetterNodeFinder $betterNodeFinder, \Rector\CodingStyle\ClassNameImport\UseImportsTraverser $useImportsTraverser, NodeNameResolver $nodeNameResolver)
{ {
$this->betterNodeFinder = $betterNodeFinder; $this->betterNodeFinder = $betterNodeFinder;
@ -53,10 +50,10 @@ final class UsedImportsResolver
$usedConstImports = []; $usedConstImports = [];
$usedFunctionImports = []; $usedFunctionImports = [];
/** @param Use_::TYPE_* $useType */ /** @param Use_::TYPE_* $useType */
$this->useImportsTraverser->traverserStmts($stmts, static function (int $useType, UseUse $useUse, string $name) use(&$usedImports, &$usedFunctionImports, &$usedConstImports) : void { $this->useImportsTraverser->traverserStmts($stmts, static function (int $useType, UseItem $useItem, string $name) use(&$usedImports, &$usedFunctionImports, &$usedConstImports) : void {
if ($useType === Use_::TYPE_NORMAL) { if ($useType === Use_::TYPE_NORMAL) {
if ($useUse->alias instanceof Identifier) { if ($useItem->alias instanceof Identifier) {
$usedImports[] = new AliasedObjectType($useUse->alias->toString(), $name); $usedImports[] = new AliasedObjectType($useItem->alias->toString(), $name);
} else { } else {
$usedImports[] = new FullyQualifiedObjectType($name); $usedImports[] = new FullyQualifiedObjectType($name);
} }

View File

@ -11,17 +11,17 @@ final class UsedImports
* @var array<(FullyQualifiedObjectType | AliasedObjectType)> * @var array<(FullyQualifiedObjectType | AliasedObjectType)>
* @readonly * @readonly
*/ */
private $useImports; private array $useImports;
/** /**
* @var FullyQualifiedObjectType[] * @var FullyQualifiedObjectType[]
* @readonly * @readonly
*/ */
private $functionImports; private array $functionImports;
/** /**
* @var FullyQualifiedObjectType[] * @var FullyQualifiedObjectType[]
* @readonly * @readonly
*/ */
private $constantImports; private array $constantImports;
/** /**
* @param array<FullyQualifiedObjectType|AliasedObjectType> $useImports * @param array<FullyQualifiedObjectType|AliasedObjectType> $useImports
* @param FullyQualifiedObjectType[] $functionImports * @param FullyQualifiedObjectType[] $functionImports

Some files were not shown because too many files have changed in this diff Show More