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:
fail-fast: false
matrix:
php_version: ['7.2', '7.3', '7.4', '8.0', '8.1']
php_version: ['7.4', '8.0', '8.1']
commands:
-
name: 'Composer Dependency'

View File

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

View File

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

View File

@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php_version: ['7.2', '7.3', '7.4', '8.0', '8.1']
php_version: ['7.4', '8.0', '8.1']
directory:
- '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:
fail-fast: false
matrix:
php_version: ['7.3']
php_version: ['7.4']
directory:
- 'e2e/rector-prefixed-rule-test'

View File

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

View File

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

View File

@ -24,5 +24,4 @@ services:
class: PHPStan\Parser\RichParser
arguments:
parser: @currentPhpVersionPhpParser
lexer: @currentPhpVersionLexer
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:
- Rector\NodeTypeResolver\Reflection\BetterReflection\RectorBetterReflectionSourceLocatorFactory
- 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/KeywordEmulator.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/Parser.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/Differ.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/JsonDecoder.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/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/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/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/ReadonlyTokenEmulator.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/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/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/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/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/ArrowFunction.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/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/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/Empty_.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/Yield_.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/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/Relative.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/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/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/LNumber.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/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/Dir.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/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/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/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/Case_.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/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/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/Do_.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/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/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/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/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/TraitUseAdaptation/Alias.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/While_.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/VariadicPlaceholder.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/NodeTraverser.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/FirstFindingVisitor.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/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/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/PhpVersion.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/NodeVisitor.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/ConstFetchNode.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/NodeVisitor/CloningVisitor.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/TokenIterator.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/Differ.php';
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Printer/Printer.php';

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,24 +10,20 @@ final class ArgumentAdderWithoutDefaultValue
{
/**
* @readonly
* @var string
*/
private $class;
private string $class;
/**
* @readonly
* @var string
*/
private $method;
private string $method;
/**
* @readonly
* @var int
*/
private $position;
private int $position;
/**
* @readonly
* @var string|null
*/
private $argumentName;
private ?string $argumentName = null;
/**
* @readonly
* @var \PHPStan\Type\Type|null
@ -35,9 +31,8 @@ final class ArgumentAdderWithoutDefaultValue
private $argumentType = null;
/**
* @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)
{
$this->class = $class;

View File

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

View File

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

View File

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

View File

@ -3,13 +3,13 @@
declare (strict_types=1);
namespace Rector\Carbon\NodeFactory;
use PhpParser\Node\Scalar\Int_;
use RectorPrefix202411\Nette\Utils\Strings;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\String_;
final class CarbonCallFactory
{
@ -32,7 +32,7 @@ final class CarbonCallFactory
$string->value = Strings::replace($string->value, self::STATIC_DATE_REGEX);
// Handle add/sub multiple times
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) {
$carbonCall = $methodCall;
$string->value = Strings::replace($string->value, self::PLUS_MINUS_COUNT_REGEX, '', 1);
@ -50,7 +50,7 @@ final class CarbonCallFactory
return $carbonCall;
}
// 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;
}
$currentCall->name = new Identifier('parse');
@ -68,7 +68,7 @@ final class CarbonCallFactory
/**
* @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) {
case 'sec':
@ -120,7 +120,7 @@ final class CarbonCallFactory
return null;
}
$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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -27,39 +27,32 @@ final class CompleteDynamicPropertiesRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\CodeQuality\NodeFactory\MissingPropertiesFactory
*/
private $missingPropertiesFactory;
private MissingPropertiesFactory $missingPropertiesFactory;
/**
* @readonly
* @var \Rector\CodeQuality\NodeAnalyzer\LocalPropertyAnalyzer
*/
private $localPropertyAnalyzer;
private LocalPropertyAnalyzer $localPropertyAnalyzer;
/**
* @readonly
* @var \Rector\CodeQuality\NodeAnalyzer\ClassLikeAnalyzer
*/
private $classLikeAnalyzer;
private ClassLikeAnalyzer $classLikeAnalyzer;
/**
* @readonly
* @var \PHPStan\Reflection\ReflectionProvider
*/
private $reflectionProvider;
private ReflectionProvider $reflectionProvider;
/**
* @readonly
* @var \Rector\NodeAnalyzer\ClassAnalyzer
*/
private $classAnalyzer;
private ClassAnalyzer $classAnalyzer;
/**
* @readonly
* @var \Rector\NodeAnalyzer\PropertyPresenceChecker
*/
private $propertyPresenceChecker;
private PropertyPresenceChecker $propertyPresenceChecker;
/**
* @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)
{
$this->missingPropertiesFactory = $missingPropertiesFactory;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@ namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
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\Identical;
use PhpParser\Node\Expr\BinaryOp\NotEqual;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodeQuality\Rector\If_;
use PhpParser\Node;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
use PhpParser\Node\Stmt\Else_;
use PhpParser\Node\Stmt\If_;
@ -22,14 +23,12 @@ final class CombineIfRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\BetterPhpDocParser\Comment\CommentsMerger
*/
private $commentsMerger;
private CommentsMerger $commentsMerger;
/**
* @readonly
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
*/
private $phpDocInfoFactory;
private PhpDocInfoFactory $phpDocInfoFactory;
public function __construct(CommentsMerger $commentsMerger, PhpDocInfoFactory $phpDocInfoFactory)
{
$this->commentsMerger = $commentsMerger;
@ -84,6 +83,13 @@ CODE_SAMPLE
return 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->stmts = $subIf->stmts;
$this->commentsMerger->keepComments($node, [$subIf]);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -39,8 +39,9 @@ CODE_SAMPLE
}
/**
* @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);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -61,12 +61,19 @@ CODE_SAMPLE
return null;
}
$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) {
$ternary = $node->if;
$ternary->setAttribute(AttributeKey::KIND, 'wrapped_with_brackets');
$ternary->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
if ($node->else instanceof Ternary) {
$ternary = $node->else;
$ternary->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
return $node;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,13 +3,13 @@
declare (strict_types=1);
namespace Rector\CodingStyle\ClassNameImport;
use PhpParser\Node\UseItem;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\GroupUse;
use PhpParser\Node\Stmt\Use_;
use PhpParser\Node\Stmt\UseUse;
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
@ -23,12 +23,11 @@ final class ClassNameImportSkipper
* @var ClassNameImportSkipVoterInterface[]
* @readonly
*/
private $classNameImportSkipVoters;
private iterable $classNameImportSkipVoters;
/**
* @readonly
* @var \Rector\Naming\Naming\UseImportsResolver
*/
private $useImportsResolver;
private UseImportsResolver $useImportsResolver;
/**
* @param ClassNameImportSkipVoterInterface[] $classNameImportSkipVoters
*/
@ -102,11 +101,11 @@ final class ClassNameImportSkipper
}
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 $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
* @var \Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser
*/
private $simpleCallableNodeTraverser;
private SimpleCallableNodeTraverser $simpleCallableNodeTraverser;
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
private NodeNameResolver $nodeNameResolver;
/**
* @readonly
* @var \Rector\PhpParser\Node\BetterNodeFinder
*/
private $betterNodeFinder;
private BetterNodeFinder $betterNodeFinder;
/**
* @readonly
* @var \Rector\CodingStyle\NodeAnalyzer\UseImportNameMatcher
*/
private $useImportNameMatcher;
private UseImportNameMatcher $useImportNameMatcher;
/**
* @readonly
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
*/
private $phpDocInfoFactory;
private PhpDocInfoFactory $phpDocInfoFactory;
/**
* @var array<string, string[]>
*/
private $shortNamesByFilePath = [];
private array $shortNamesByFilePath = [];
public function __construct(SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeNameResolver $nodeNameResolver, BetterNodeFinder $betterNodeFinder, UseImportNameMatcher $useImportNameMatcher, PhpDocInfoFactory $phpDocInfoFactory)
{
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
@ -84,9 +79,7 @@ final class ShortNameResolver
{
$newStmts = $file->getNewStmts();
/** @var Namespace_[]|FileWithoutNamespace[] $namespaces */
$namespaces = \array_filter($newStmts, static function (Stmt $stmt) : bool {
return $stmt instanceof Namespace_ || $stmt instanceof FileWithoutNamespace;
});
$namespaces = \array_filter($newStmts, static fn(Stmt $stmt): bool => $stmt instanceof Namespace_ || $stmt instanceof FileWithoutNamespace);
if (\count($namespaces) !== 1) {
// only handle single namespace nodes
return [];

View File

@ -3,27 +3,26 @@
declare (strict_types=1);
namespace Rector\CodingStyle\ClassNameImport;
use PhpParser\Node\UseItem;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\GroupUse;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\Use_;
use PhpParser\Node\Stmt\UseUse;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace;
final class UseImportsTraverser
{
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
private NodeNameResolver $nodeNameResolver;
public function __construct(NodeNameResolver $nodeNameResolver)
{
$this->nodeNameResolver = $nodeNameResolver;
}
/**
* @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
{
@ -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
{

View File

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

View File

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

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