Skip to content

Commit

Permalink
drop uses of instanceof NullType
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Nov 7, 2022
1 parent 85cc1ff commit aaa752a
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ private function resolveType(Expr $node): Type
$node->left instanceof Node\Expr\PropertyFetch
|| $node->left instanceof Node\Expr\StaticPropertyFetch
)
&& $rightType instanceof NullType
&& $rightType->isNull()->yes()
&& !$this->hasPropertyNativeType($node->left)
) {
return new BooleanType();
Expand All @@ -886,7 +886,7 @@ private function resolveType(Expr $node): Type
$node->right instanceof Node\Expr\PropertyFetch
|| $node->right instanceof Node\Expr\StaticPropertyFetch
)
&& $leftType instanceof NullType
&& $leftType->isNull()->yes()
&& !$this->hasPropertyNativeType($node->right)
) {
return new BooleanType();
Expand Down
2 changes: 1 addition & 1 deletion src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2167,7 +2167,7 @@ static function (?Type $offsetType, Type $valueType, bool $optional) use (&$arra
$thisType = null;
if (isset($expr->getArgs()[1])) {
$argType = $scope->getType($expr->getArgs()[1]->value);
if ($argType instanceof NullType) {
if ($argType->isNull()->yes()) {
$thisType = null;
} else {
$thisType = $argType;
Expand Down
3 changes: 1 addition & 2 deletions src/Reflection/Php/PhpParameterFromParserNodeReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use PHPStan\Reflection\ParameterReflectionWithPhpDocs;
use PHPStan\Reflection\PassedByReference;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypehintHelper;
Expand Down Expand Up @@ -43,7 +42,7 @@ public function getType(): Type
if ($this->type === null) {
$phpDocType = $this->phpDocType;
if ($phpDocType !== null && $this->defaultValue !== null) {
if ($this->defaultValue instanceof NullType) {
if ($this->defaultValue->isNull()->yes()) {
$inferred = $phpDocType->inferTemplateTypes($this->defaultValue);
if ($inferred->isEmpty()) {
$phpDocType = TypeCombinator::addNull($phpDocType);
Expand Down
3 changes: 1 addition & 2 deletions src/Reflection/Php/PhpParameterReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use PHPStan\Reflection\ParameterReflectionWithPhpDocs;
use PHPStan\Reflection\PassedByReference;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypehintHelper;
Expand Down Expand Up @@ -52,7 +51,7 @@ public function getType(): Type
$this->reflection->getDefaultValueExpression(),
InitializerExprContext::fromReflectionParameter($this->reflection),
);
if ($defaultValueType instanceof NullType) {
if ($defaultValueType->isNull()->yes()) {
$phpDocType = TypeCombinator::addNull($phpDocType);
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/Rules/Operators/InvalidComparisonOperationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use PHPStan\Type\ErrorType;
use PHPStan\Type\FloatType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
Expand Down Expand Up @@ -106,7 +105,7 @@ private function isPossiblyNullableObjectType(Scope $scope, Node\Expr $expr): bo
return false;
}

if (TypeCombinator::containsNull($type) && !$type instanceof NullType) {
if (TypeCombinator::containsNull($type) && !$type->isNull()->yes()) {
$type = TypeCombinator::removeNull($type);
}

Expand All @@ -127,7 +126,7 @@ private function isPossiblyNullableArrayType(Scope $scope, Node\Expr $expr): boo
static fn (Type $type): bool => $type->isArray()->yes(),
)->getType();

if (TypeCombinator::containsNull($type) && !$type instanceof NullType) {
if (TypeCombinator::containsNull($type) && !$type->isNull()->yes()) {
$type = TypeCombinator::removeNull($type);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/RuleLevelHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function findTypeToCheck(
return new FoundTypeResult(new ErrorType(), [], [], null);
}
$type = $scope->getType($var);
if (!$this->checkNullables && !$type instanceof NullType) {
if (!$this->checkNullables && !$type->isNull()->yes()) {
$type = TypeCombinator::removeNull($type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use PHPStan\Node\InArrowFunctionNode;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\NullType;
use PHPStan\Type\UnionType;
use PHPStan\Type\VerbosityLevel;
use function sprintf;
Expand Down Expand Up @@ -40,7 +39,7 @@ public function processNode(Node $node, Scope $scope): array
}

$returnType = $scope->getType($expr);
if ($returnType instanceof NullType) {
if ($returnType->isNull()->yes()) {
return [];
}
$messages = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use PHPStan\Node\ClosureReturnStatementsNode;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\NullType;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\UnionType;
use PHPStan\Type\VerbosityLevel;
Expand Down Expand Up @@ -62,7 +61,7 @@ public function processNode(Node $node, Scope $scope): array
}

$returnType = TypeCombinator::union(...$returnTypes);
if ($returnType instanceof NullType) {
if ($returnType->isNull()->yes()) {
return [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\NullType;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\UnionType;
use PHPStan\Type\VerbosityLevel;
Expand Down Expand Up @@ -71,7 +70,7 @@ public function processNode(Node $node, Scope $scope): array
continue;
}

if ($type instanceof NullType && !$node->hasNativeReturnTypehint()) {
if ($type->isNull()->yes() && !$node->hasNativeReturnTypehint()) {
foreach ($node->getExecutionEnds() as $executionEnd) {
if ($executionEnd->getStatementResult()->isAlwaysTerminating()) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\NullType;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\UnionType;
use PHPStan\Type\VerbosityLevel;
Expand Down Expand Up @@ -80,7 +79,7 @@ public function processNode(Node $node, Scope $scope): array
$returnType = TypeCombinator::union(...$returnTypes);
if (
!$method->isPrivate()
&& ($returnType instanceof NullType || $returnType instanceof ConstantBooleanType)
&& ($returnType->isNull()->yes() || $returnType instanceof ConstantBooleanType)
&& !$isFirstDeclaration
) {
return [];
Expand All @@ -92,7 +91,7 @@ public function processNode(Node $node, Scope $scope): array
continue;
}

if ($type instanceof NullType && !$node->hasNativeReturnTypehint()) {
if ($type->isNull()->yes() && !$node->hasNativeReturnTypehint()) {
foreach ($node->getExecutionEnds() as $executionEnd) {
if ($executionEnd->getStatementResult()->isAlwaysTerminating()) {
continue;
Expand Down

0 comments on commit aaa752a

Please sign in to comment.