Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,5 @@ parameters:
-
message: '#Unable to resolve the template type T in call to static method Webmozart\\Assert\\Assert\:\:isInstanceOfAny\(\)#'
path: rules/DeadCode/Rector/FunctionLike/NarrowWideUnionReturnTypeRector.php

- '#Provide more specific return type "Iterator|PhpParser\\Node" over abstract one#'
1 change: 0 additions & 1 deletion rules/CodeQuality/Rector/Assign/CombinedAssignRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public function refactor(Node $node): ?Node
return null;
}

/** @var BinaryOp $binaryNode */
$binaryNode = $node->expr;

if (! $this->nodeComparator->areNodesEqual($node->var, $binaryNode->left)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public function refactor(Node $node): ?Node
return null;
}

/** @var FuncCall $innerFuncCall */
$innerFuncCall = $firstArg->value;

if (! $this->isName($innerFuncCall, 'func_get_args')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public function refactor(Node $node): ?Node
return null;
}

/** @var FuncCall $innerFunCall */
$innerFunCall = $node->args[1]->value;
if (! $this->isName($innerFunCall, 'array_values')) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public function refactor(Node $node): ?Node
return null;
}

/** @var FuncCall $innerFuncCall */
$innerFuncCall = $firstArg->value;
if (! $this->isName($innerFuncCall, 'strtolower')) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ private function resolveArrayItem(FuncCall $funcCall): ?ArrayItem
return null;
}

/** @var Array_ $arrayNode */
$arrayNode = $funcCall->args[1]->value;
if (count($arrayNode->items) !== 1) {
return null;
Expand Down
2 changes: 0 additions & 2 deletions rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ private function resolveIdentical(Expr $expr, bool $isNegated, String_ $string):
{
/**
* // compare === ''
*
* @var Identical|NotIdentical
*/
$identical = $isNegated
? new Identical($expr, $string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public function refactor(Node $node): ?Node
return null;
}

/** @var Assign $assign */
$assign = $stmt->expr;

// has non property fetches assignments, skip
Expand Down
3 changes: 0 additions & 3 deletions rules/DeadCode/Rector/Expression/RemoveDeadStmtRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use PhpParser\Comment\Doc;
use PhpParser\Node;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Nop;
use PhpParser\NodeVisitor;
Expand Down Expand Up @@ -93,7 +91,6 @@ private function hasGetMagic(Expression $expression): bool
return false;
}

/** @var PropertyFetch|StaticPropertyFetch $propertyFetch */
$propertyFetch = $expression->expr;
$phpPropertyReflection = $this->reflectionResolver->resolvePropertyReflectionFromPropertyFetch($propertyFetch);

Expand Down
3 changes: 0 additions & 3 deletions rules/DeadCode/UselessIfCondBeforeForeachDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function isMatchingEmptyAndForeachedExpr(If_ $if, Expr $foreachExpr): boo
return false;
}

/** @var Empty_ $empty */
$empty = $if->cond;

if (! $this->nodeComparator->areNodesEqual($empty->expr, $foreachExpr)) {
Expand Down Expand Up @@ -66,7 +65,6 @@ public function isMatchingNotEmpty(If_ $if, Expr $foreachExpr, Scope $scope): bo
return false;
}

/** @var Empty_ $empty */
$empty = $cond->expr;

return $this->areCondExprAndForeachExprSame($empty, $foreachExpr, $scope);
Expand All @@ -85,7 +83,6 @@ public function isMatchingNotIdenticalEmptyArray(If_ $if, Expr $foreachExpr): bo
return false;
}

/** @var NotIdentical|NotEqual $notIdentical */
$notIdentical = $if->cond;

return $this->isMatchingNotBinaryOp($notIdentical, $foreachExpr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public function refactor(Node $node): ?Node
continue;
}

/** @var BooleanOr $booleanOr */
$booleanOr = $stmt->expr;

$left = $booleanOr->left;
Expand Down
2 changes: 0 additions & 2 deletions rules/Naming/Naming/ExpectedNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public function resolveForAssignNonNew(Assign $assign): ?string
return null;
}

/** @var Variable $variable */
$variable = $assign->var;

return $this->nodeNameResolver->getName($variable);
Expand All @@ -79,7 +78,6 @@ public function resolveForAssignNew(Assign $assign): ?string
return null;
}

/** @var New_ $new */
$new = $assign->expr;
if (! $new->class instanceof Name) {
return null;
Expand Down
1 change: 0 additions & 1 deletion rules/Php70/Rector/FuncCall/EregToPregMatchRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ private function processSplitLimitArgument(FuncCall $funcCall, string $functionN
return;
}

/** @var Int_ $limitNumberNode */
$limitNumberNode = $funcCall->args[2]->value;
if ($limitNumberNode->value !== 0) {
return;
Expand Down
1 change: 0 additions & 1 deletion rules/Php70/Rector/FuncCall/MultiDirnameRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ private function matchNestedDirnameFuncCall(FuncCall $funcCall): ?FuncCall
return null;
}

/** @var Int_ $levelNumber */
$levelNumber = $args[1]->value;

$this->nestingLevel += $levelNumber->value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public function refactor(Node $node): ?Node
return null;
}

/** @var Identical|NotIdentical $ternaryCompareNode */
$ternaryCompareNode = $node->cond;
if ($this->isNullMatch($ternaryCompareNode->left, $ternaryCompareNode->right, $checkedNode)) {
return new Coalesce($checkedNode, $fallbackNode);
Expand Down
1 change: 0 additions & 1 deletion rules/Php73/Rector/FuncCall/ArrayKeyFirstLastRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ private function processArrayKeyFirstLast(Node $stmtsAware, int $jumpToKey = 0):
continue;
}

/** @var Expression $stmt */
$stmt = $stmtsAware->stmts[$key];
if ($this->shouldSkip($stmt)) {
continue;
Expand Down
1 change: 0 additions & 1 deletion rules/Php74/NodeAnalyzer/ClosureArrowFunctionAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public function matchArrowFunctionExpr(Closure $closure): ?Expr
return null;
}

/** @var Return_ $return */
$return = $onlyStmt;
if (! $return->expr instanceof Expr) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function match(Identical|NotIdentical|Equal|NotEqual $binaryOp): ?StrStar
$isPositive = $binaryOp instanceof Identical || $binaryOp instanceof Equal;

if ($binaryOp->left instanceof FuncCall && $this->nodeNameResolver->isName($binaryOp->left, 'substr')) {
/** @var FuncCall $funcCall */
$funcCall = $binaryOp->left;

$haystack = $funcCall->getArgs()[0]
Expand All @@ -44,7 +43,6 @@ public function match(Identical|NotIdentical|Equal|NotEqual $binaryOp): ?StrStar
}

if ($binaryOp->right instanceof FuncCall && $this->nodeNameResolver->isName($binaryOp->right, 'substr')) {
/** @var FuncCall $funcCall */
$funcCall = $binaryOp->right;

$haystack = $funcCall->getArgs()[0]
Expand Down
8 changes: 2 additions & 6 deletions rules/Php80/NodeResolver/StrFalseComparisonResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public function resolve(Identical | NotIdentical | Equal | NotEqual $expr, array
return null;
}

/** @var FuncCall $funcCall */
$funcCall = $expr->right;
return $funcCall;
return $expr->right;
}

if ($this->valueResolver->isFalse($expr->right)) {
Expand All @@ -48,9 +46,7 @@ public function resolve(Identical | NotIdentical | Equal | NotEqual $expr, array
return null;
}

/** @var FuncCall $funcCall */
$funcCall = $expr->left;
return $funcCall;
return $expr->left;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Reflection\Php\PhpPropertyReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
Expand Down Expand Up @@ -88,7 +87,6 @@ private function resolvePropertyFetchProvidingType(
$nativeReflectionClass = $classReflection->getNativeReflection();

foreach ($nativeReflectionClass->getProperties() as $reflectionProperty) {
/** @var PhpPropertyReflection $phpPropertyReflection */
$phpPropertyReflection = $classReflection->getNativeProperty($reflectionProperty->getName());

$readableType = $phpPropertyReflection->getReadableType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function hasPropertyFetchReturn(ClassMethod $classMethod, string $propert
return false;
}

/** @var Return_ $return */
$return = $onlyClassMethodStmt;

if (! $return->expr instanceof PropertyFetch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ private function resolveScalarArrayTypeForVariable(ClassMethod|Function_ $node,
continue;
}

/** @var ArrayDimFetch $arrayDimFetch */
$arrayDimFetch = $assign->var;
if (! $arrayDimFetch->var instanceof Variable) {
continue;
Expand All @@ -213,7 +212,7 @@ private function resolveScalarArrayTypeForVariable(ClassMethod|Function_ $node,
continue;
}

if ($arrayDimFetch->dim !== null) {
if ($arrayDimFetch->dim instanceof Expr) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public function refactor(Node $node): ?Node
return null;
}

/** @var MethodCall $returnExpr */
$returnExpr = $node->stmts[0]->expr;
if (! $this->isName($returnExpr->name, 'deserialize')) {
return null;
Expand Down
2 changes: 0 additions & 2 deletions src/NodeManipulator/ClassDependencyManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public function addConstructorDependencyWithCustomAssign(
?Type $type,
Assign $assign
): void {
/** @var ClassMethod|null $constructClassMethod */
$constructClassMethod = $this->resolveConstruct($class);

if ($constructClassMethod instanceof ClassMethod) {
Expand Down Expand Up @@ -190,7 +189,6 @@ public function addStmtsToConstructorIfNotThereYet(Class_ $class, array $stmts):

private function resolveConstruct(Class_ $class): ?ClassMethod
{
/** @var ClassMethod|null $constructorMethod */
$constructorMethod = $class->getMethod(MethodName::CONSTRUCT);

// exists in current class
Expand Down
1 change: 0 additions & 1 deletion src/NodeTypeResolver/NodeTypeResolver/NewTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ private function resolveAnonymousClassType(New_ $new): ObjectWithoutClassType

$directParentTypes = [];

/** @var Class_ $class */
$class = $new->class;
if ($class->extends instanceof Name) {
$parentClass = (string) $class->extends;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ public function processNodes(
// the class reflection is resolved AFTER entering to class node
// so we need to get it from the first after this one
if ($node instanceof Class_ || $node instanceof Interface_ || $node instanceof Enum_) {
/** @var MutatingScope $mutatingScope */
$mutatingScope = $this->resolveClassOrInterfaceScope($node, $mutatingScope);
$node->setAttribute(AttributeKey::SCOPE, $mutatingScope);

Expand Down
18 changes: 18 additions & 0 deletions src/StaticTypeMapper/ValueObject/Type/FullyQualifiedObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
namespace Rector\StaticTypeMapper\ValueObject\Type;

use Nette\Utils\Strings;
use Override;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Use_;
use PhpParser\Node\UseItem;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Rector\NodeTypeResolver\Node\AttributeKey;

/**
Expand Down Expand Up @@ -64,4 +66,20 @@ public function getShortNameLowered(): string
{
return strtolower($this->getShortName());
}

#[Override]
public function equals(Type $type): bool
{
$isEqual = parent::equals($type);

if ($isEqual) {
return true;
}

if ($type instanceof self || $type::class === ObjectType::class) {
return $type->getClassName() === $this->getClassName();
}

return false;
}
}
17 changes: 17 additions & 0 deletions src/StaticTypeMapper/ValueObject/Type/NonExistingObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@

namespace Rector\StaticTypeMapper\ValueObject\Type;

use Override;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;

final class NonExistingObjectType extends ObjectType
{
#[Override]
public function equals(Type $type): bool
{
$isEqual = parent::equals($type);

if ($isEqual) {
return true;
}

if ($type instanceof self || $type::class === ObjectType::class) {
return $type->getClassName() === $this->getClassName();
}

return false;
}
}
16 changes: 16 additions & 0 deletions src/StaticTypeMapper/ValueObject/Type/ShortenedObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,20 @@ public function getFullyQualifiedName(): string
{
return $this->fullyQualifiedName;
}

#[Override]
public function equals(Type $type): bool
{
$isEqual = parent::equals($type);

if ($isEqual) {
return true;
}

if ($type instanceof self || $type::class === ObjectType::class) {
return $type->getClassName() === $this->fullyQualifiedName;
}

return false;
}
}
Loading