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
18 changes: 18 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,18 @@ parameters:
count: 1
path: src/Type/IterableType.php

-
rawMessage: 'Doing instanceof PHPStan\Type\NeverType is error-prone and deprecated. Use Type::isNever() or Type::isExplicitNever() instead.'
identifier: phpstanApi.instanceofType
count: 2
path: src/Type/NeverType.php

-
rawMessage: 'Doing instanceof PHPStan\Type\NeverType is error-prone and deprecated. Use Type::isNever() or Type::isExplicitNever() instead.'
identifier: phpstanApi.instanceofType
count: 1
path: src/Type/NonAcceptingNeverType.php

-
rawMessage: 'Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.'
identifier: phpstanApi.instanceofType
Expand Down Expand Up @@ -1785,6 +1797,12 @@ parameters:
count: 1
path: src/Type/TypehintHelper.php

-
rawMessage: 'Call to an undefined method PHPStan\Type\Type::isSubTypeOf().'
identifier: method.notFound
count: 1
path: src/Type/UnionType.php

-
rawMessage: 'Doing instanceof PHPStan\Type\CallableType is error-prone and deprecated. Use Type::isCallable() and Type::getCallableParametersAcceptors() instead.'
identifier: phpstanApi.instanceofType
Expand Down
12 changes: 6 additions & 6 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ private function resolveType(string $exprString, Expr $node): Type
) {
return new BooleanType();
}
if ($expressionType instanceof NeverType) {
if (!$expressionType->isNever()->no()) {
return new ConstantBooleanType(false);
}

Expand Down Expand Up @@ -4578,8 +4578,8 @@ public function removeTypeFromExpression(Expr $expr, Type $typeToRemove): self
{
$exprType = $this->getType($expr);
if (
$exprType instanceof NeverType ||
$typeToRemove instanceof NeverType
!$exprType->isNever()->no() ||
!$typeToRemove->isNever()->no()
) {
return $this;
}
Expand Down Expand Up @@ -5891,7 +5891,7 @@ private function exactInstantiation(New_ $node, string $className): ?Type
}

$methodResult = $this->getType($methodCall);
if ($methodResult instanceof NeverType && $methodResult->isExplicit()) {
if ($methodResult->isExplicitNever()->yes()) {
return $methodResult;
}

Expand Down Expand Up @@ -6347,7 +6347,7 @@ public function getIterableKeyType(Type $iteratee): Type
{
if ($iteratee instanceof UnionType) {
$filtered = $iteratee->filterTypes(static fn (Type $innerType) => $innerType->isIterable()->yes());
if (!$filtered instanceof NeverType) {
if ($filtered->isNever()->no()) {
$iteratee = $filtered;
}
}
Expand All @@ -6359,7 +6359,7 @@ public function getIterableValueType(Type $iteratee): Type
{
if ($iteratee instanceof UnionType) {
$filtered = $iteratee->filterTypes(static fn (Type $innerType) => $innerType->isIterable()->yes());
if (!$filtered instanceof NeverType) {
if ($filtered->isNever()->no()) {
$iteratee = $filtered;
}
}
Expand Down
34 changes: 17 additions & 17 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@ private function processStmtNode(
}
}

$exhaustive = $scopeForBranches->getType($stmt->cond) instanceof NeverType;
$exhaustive = $scopeForBranches->getType($stmt->cond)->isNever()->yes();

if (!$hasDefaultCase && !$exhaustive) {
$alwaysTerminating = false;
Expand Down Expand Up @@ -1893,7 +1893,7 @@ private function processStmtNode(
foreach ($throwPoints as $throwPoint) {
$newThrowPoint = $throwPoint->subtractCatchType($originalCatchType);

if ($newThrowPoint->getType() instanceof NeverType) {
if (!$newThrowPoint->getType()->isNever()->no()) {
continue;
}

Expand Down Expand Up @@ -2489,7 +2489,7 @@ private function findEarlyTerminatingExpr(Expr $expr, Scope $scope): ?Expr
}

$exprType = $scope->getType($expr);
if ($exprType instanceof NeverType && $exprType->isExplicit()) {
if ($exprType->isExplicitNever()->yes()) {
return $expr;
}

Expand Down Expand Up @@ -2709,7 +2709,7 @@ static function (): void {
if ($parametersAcceptor !== null) {
$expr = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $expr) ?? $expr;
$returnType = $parametersAcceptor->getReturnType();
$isAlwaysTerminating = $isAlwaysTerminating || $returnType instanceof NeverType && $returnType->isExplicit();
$isAlwaysTerminating = $isAlwaysTerminating || $returnType->isExplicitNever()->yes();
}

if (
Expand Down Expand Up @@ -3032,7 +3032,7 @@ static function (): void {
if ($parametersAcceptor !== null) {
$expr = ArgumentsNormalizer::reorderMethodArguments($parametersAcceptor, $expr) ?? $expr;
$returnType = $parametersAcceptor->getReturnType();
$isAlwaysTerminating = $returnType instanceof NeverType && $returnType->isExplicit();
$isAlwaysTerminating = $returnType->isExplicitNever()->yes();
}

$result = $this->processArgs(
Expand Down Expand Up @@ -3224,7 +3224,7 @@ static function (): void {
if ($parametersAcceptor !== null) {
$expr = ArgumentsNormalizer::reorderStaticCallArguments($parametersAcceptor, $expr) ?? $expr;
$returnType = $parametersAcceptor->getReturnType();
$isAlwaysTerminating = $returnType instanceof NeverType && $returnType->isExplicit();
$isAlwaysTerminating = $returnType->isExplicitNever()->yes();
}
$result = $this->processArgs($stmt, $methodReflection, null, $parametersAcceptor, $expr, $scope, $nodeCallback, $context, $closureBindScope ?? null);
$scope = $result->getScope();
Expand Down Expand Up @@ -3450,7 +3450,7 @@ static function (): void {
$leftResult = $this->processExprNode($stmt, $expr->left, $scope, $nodeCallback, $context->enterDeep());
$rightResult = $this->processExprNode($stmt, $expr->right, $leftResult->getTruthyScope(), $nodeCallback, $context);
$rightExprType = $rightResult->getScope()->getType($expr->right);
if ($rightExprType instanceof NeverType && $rightExprType->isExplicit()) {
if ($rightExprType->isExplicitNever()->yes()) {
$leftMergedWithRightScope = $leftResult->getFalseyScope();
} else {
$leftMergedWithRightScope = $leftResult->getScope()->mergeWith($rightResult->getScope());
Expand All @@ -3471,7 +3471,7 @@ static function (): void {
$leftResult = $this->processExprNode($stmt, $expr->left, $scope, $nodeCallback, $context->enterDeep());
$rightResult = $this->processExprNode($stmt, $expr->right, $leftResult->getFalseyScope(), $nodeCallback, $context);
$rightExprType = $rightResult->getScope()->getType($expr->right);
if ($rightExprType instanceof NeverType && $rightExprType->isExplicit()) {
if ($rightExprType->isExplicitNever()->yes()) {
$leftMergedWithRightScope = $leftResult->getTruthyScope();
} else {
$leftMergedWithRightScope = $leftResult->getScope()->mergeWith($rightResult->getScope());
Expand All @@ -3498,7 +3498,7 @@ static function (): void {
$rightScope = $scope->filterByFalseyValue($expr);
$rightResult = $this->processExprNode($stmt, $expr->right, $rightScope, $nodeCallback, $context->enterDeep());
$rightExprType = $scope->getType($expr->right);
if ($rightExprType instanceof NeverType && $rightExprType->isExplicit()) {
if ($rightExprType->isExplicitNever()->yes()) {
$scope = $scope->filterByTruthyValue(new Expr\Isset_([$expr->left]));
} else {
$scope = $scope->filterByTruthyValue(new Expr\Isset_([$expr->left]))->mergeWith($rightResult->getScope());
Expand Down Expand Up @@ -3936,12 +3936,12 @@ static function (): void {
} elseif ($condType->isFalse()->yes()) {
$finalScope = $ifFalseScope;
} else {
if ($ifTrueType instanceof NeverType && $ifTrueType->isExplicit()) {
if ($ifTrueType !== null && $ifTrueType->isExplicitNever()->yes()) {
$finalScope = $ifFalseScope;
} else {
$ifFalseType = $ifFalseScope->getType($expr->else);

if ($ifFalseType instanceof NeverType && $ifFalseType->isExplicit()) {
if ($ifFalseType->isExplicitNever()->yes()) {
$finalScope = $ifTrueScope;
} else {
$finalScope = $ifTrueScope->mergeWith($ifFalseScope);
Expand Down Expand Up @@ -4196,7 +4196,7 @@ static function (): void {
}

$remainingType = $matchScope->getType($expr->cond);
if (!$hasDefaultCond && !$hasAlwaysTrueCond && !$remainingType instanceof NeverType) {
if (!$hasDefaultCond && !$hasAlwaysTrueCond && $remainingType->isNever()->no()) {
$throwPoints[] = ThrowPoint::createExplicit($scope, new ObjectType(UnhandledMatchError::class), $expr, false);
}

Expand Down Expand Up @@ -4502,7 +4502,7 @@ private function getFunctionThrowPoint(
$throwType = $functionReflection->getThrowType();
if ($throwType === null && $parametersAcceptor !== null) {
$returnType = $parametersAcceptor->getReturnType();
if ($returnType instanceof NeverType && $returnType->isExplicit()) {
if ($returnType->isExplicitNever()->yes()) {
$throwType = new ObjectType(Throwable::class);
}
}
Expand Down Expand Up @@ -4560,7 +4560,7 @@ private function getMethodThrowPoint(MethodReflection $methodReflection, Paramet
$throwType = $methodReflection->getThrowType();
if ($throwType === null) {
$returnType = $parametersAcceptor->getReturnType();
if ($returnType instanceof NeverType && $returnType->isExplicit()) {
if ($returnType->isExplicitNever()->yes()) {
$throwType = new ObjectType(Throwable::class);
}
}
Expand Down Expand Up @@ -4857,7 +4857,7 @@ private function processClosureNode(
}

$returnType = $closureType->getReturnType();
$isAlwaysTerminating = ($returnType instanceof NeverType && $returnType->isExplicit());
$isAlwaysTerminating = ($returnType->isExplicitNever()->yes());

$nodeCallback(new InClosureNode($closureType, $expr), $closureScope);

Expand Down Expand Up @@ -5545,7 +5545,7 @@ private function processArgs(
$throwPoints = array_merge($throwPoints, $callableThrowPoints);
$impurePoints = array_merge($impurePoints, array_map(static fn (SimpleImpurePoint $impurePoint) => new ImpurePoint($scope, $arg->value, $impurePoint->getIdentifier(), $impurePoint->getDescription(), $impurePoint->isCertain()), $acceptors[0]->getImpurePoints()));
$returnType = $acceptors[0]->getReturnType();
$isAlwaysTerminating = $isAlwaysTerminating || ($returnType instanceof NeverType && $returnType->isExplicit());
$isAlwaysTerminating = $isAlwaysTerminating || ($returnType->isExplicitNever()->yes());
}
}
}
Expand Down Expand Up @@ -6961,7 +6961,7 @@ private function processCalledMethod(MethodReflection $methodReflection): ?Mutat
$endNode = $executionEnd->getNode();
if ($endNode instanceof Node\Stmt\Expression) {
$exprType = $statementResult->getScope()->getType($endNode->expr);
if ($exprType instanceof NeverType && $exprType->isExplicit()) {
if ($exprType->isExplicitNever()->yes()) {
continue;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Node/ClassPropertiesNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use PHPStan\Reflection\MethodReflection;
use PHPStan\Rules\Properties\ReadWritePropertiesExtensionProvider;
use PHPStan\TrinaryLogic;
use PHPStan\Type\NeverType;
use PHPStan\Type\TypeUtils;
use function array_diff_key;
use function array_key_exists;
Expand Down Expand Up @@ -276,7 +275,7 @@ private function collectUninitializedProperties(array $constructors, array $unin
if ($statementResult->isAlwaysTerminating()) {
if ($endNode instanceof Node\Stmt\Expression) {
$exprType = $statementResult->getScope()->getType($endNode->expr);
if ($exprType instanceof NeverType && $exprType->isExplicit()) {
if ($exprType->isExplicitNever()->yes()) {
continue;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Reflection/Callables/FunctionCallableVariant.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PHPStan\TrinaryLogic;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\Generic\TemplateTypeVarianceMap;
use PHPStan\Type\NeverType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Throwable;
Expand Down Expand Up @@ -97,7 +96,7 @@ public function getThrowPoints(): array
$returnType = $this->variant->getReturnType();
$throwType = $this->function->getThrowType();
if ($throwType === null) {
if ($returnType instanceof NeverType && $returnType->isExplicit()) {
if ($returnType->isExplicitNever()->yes()) {
$throwType = new ObjectType(Throwable::class);
}
}
Expand Down
26 changes: 13 additions & 13 deletions src/Reflection/InitializerExprTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ public function createFirstClassCallable(
$returnTypeForThrow = $variant->getReturnType();
$throwType = $function->getThrowType();
if ($throwType === null) {
if ($returnTypeForThrow instanceof NeverType && $returnTypeForThrow->isExplicit()) {
if ($returnTypeForThrow->isExplicitNever()->yes()) {
$throwType = new ObjectType(Throwable::class);
}
}
Expand Down Expand Up @@ -954,7 +954,7 @@ public function getBitwiseAndType(Expr $left, Expr $right, callable $getTypeCall
$leftType = $getTypeCallback($left);
$rightType = $getTypeCallback($right);

if ($leftType instanceof NeverType || $rightType instanceof NeverType) {
if ($leftType->isNever()->yes() || $rightType->isNever()->yes()) {
return $this->getNeverType($leftType, $rightType);
}

Expand Down Expand Up @@ -1023,7 +1023,7 @@ public function getBitwiseOrType(Expr $left, Expr $right, callable $getTypeCallb
$leftType = $getTypeCallback($left);
$rightType = $getTypeCallback($right);

if ($leftType instanceof NeverType || $rightType instanceof NeverType) {
if ($leftType->isNever()->yes() || $rightType->isNever()->yes()) {
return $this->getNeverType($leftType, $rightType);
}

Expand Down Expand Up @@ -1082,7 +1082,7 @@ public function getBitwiseXorType(Expr $left, Expr $right, callable $getTypeCall
$leftType = $getTypeCallback($left);
$rightType = $getTypeCallback($right);

if ($leftType instanceof NeverType || $rightType instanceof NeverType) {
if ($leftType->isNever()->yes() || $rightType->isNever()->yes()) {
return $this->getNeverType($leftType, $rightType);
}

Expand Down Expand Up @@ -1141,7 +1141,7 @@ public function getSpaceshipType(Expr $left, Expr $right, callable $getTypeCallb
$callbackLeftType = $getTypeCallback($left);
$callbackRightType = $getTypeCallback($right);

if ($callbackLeftType instanceof NeverType || $callbackRightType instanceof NeverType) {
if ($callbackLeftType->isNever()->yes() || $callbackRightType->isNever()->yes()) {
return $this->getNeverType($callbackLeftType, $callbackRightType);
}

Expand Down Expand Up @@ -1228,7 +1228,7 @@ public function getModType(Expr $left, Expr $right, callable $getTypeCallback):
$leftType = $getTypeCallback($left);
$rightType = $getTypeCallback($right);

if ($leftType instanceof NeverType || $rightType instanceof NeverType) {
if ($leftType->isNever()->yes() || $rightType->isNever()->yes()) {
return $this->getNeverType($leftType, $rightType);
}

Expand Down Expand Up @@ -1337,7 +1337,7 @@ public function getPlusType(Expr $left, Expr $right, callable $getTypeCallback):
$leftType = $getTypeCallback($left);
$rightType = $getTypeCallback($right);

if ($leftType instanceof NeverType || $rightType instanceof NeverType) {
if ($leftType->isNever()->yes() || $rightType->isNever()->yes()) {
return $this->getNeverType($leftType, $rightType);
}

Expand Down Expand Up @@ -1645,7 +1645,7 @@ public function getShiftLeftType(Expr $left, Expr $right, callable $getTypeCallb
$leftType = $getTypeCallback($left);
$rightType = $getTypeCallback($right);

if ($leftType instanceof NeverType || $rightType instanceof NeverType) {
if ($leftType->isNever()->yes() || $rightType->isNever()->yes()) {
return $this->getNeverType($leftType, $rightType);
}

Expand Down Expand Up @@ -1704,7 +1704,7 @@ public function getShiftRightType(Expr $left, Expr $right, callable $getTypeCall
$leftType = $getTypeCallback($left);
$rightType = $getTypeCallback($right);

if ($leftType instanceof NeverType || $rightType instanceof NeverType) {
if ($leftType->isNever()->yes() || $rightType->isNever()->yes()) {
return $this->getNeverType($leftType, $rightType);
}

Expand Down Expand Up @@ -1787,7 +1787,7 @@ private function optimizeScalarType(Type $type): Type
*/
public function resolveIdenticalType(Type $leftType, Type $rightType): TypeResult
{
if ($leftType instanceof NeverType || $rightType instanceof NeverType) {
if ($leftType->isNever()->yes() || $rightType->isNever()->yes()) {
return new TypeResult(new ConstantBooleanType(false), []);
}

Expand Down Expand Up @@ -1969,7 +1969,7 @@ private function resolveCommonMath(Expr\BinaryOp $expr, Type $leftType, Type $ri
if ($leftNumberType instanceof ErrorType || $rightNumberType instanceof ErrorType) {
return new ErrorType();
}
if ($leftNumberType instanceof NeverType || $rightNumberType instanceof NeverType) {
if ($leftNumberType->isNever()->yes() || $rightNumberType->isNever()->yes()) {
return $this->getNeverType($leftNumberType, $rightNumberType);
}

Expand Down Expand Up @@ -2587,10 +2587,10 @@ private function getReflectionProvider(): ReflectionProvider
private function getNeverType(Type $leftType, Type $rightType): Type
{
// make sure we don't lose the explicit flag in the process
if ($leftType instanceof NeverType && $leftType->isExplicit()) {
if ($leftType->isExplicitNever()->yes()) {
return $leftType;
}
if ($rightType instanceof NeverType && $rightType->isExplicit()) {
if ($rightType->isExplicitNever()->yes()) {
return $rightType;
}
return new NeverType();
Expand Down
3 changes: 1 addition & 2 deletions src/Reflection/Php/PhpClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\Generic\TemplateTypeVariance;
use PHPStan\Type\MixedType;
use PHPStan\Type\NeverType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypehintHelper;
Expand Down Expand Up @@ -1161,7 +1160,7 @@ private function inferAndCachePropertyTypes(
}

$propertyType = $methodScope->getType($expr->expr);
if ($propertyType instanceof ErrorType || $propertyType instanceof NeverType) {
if ($propertyType instanceof ErrorType || !$propertyType->isNever()->no()) {
continue;
}

Expand Down
Loading
Loading