Skip to content
Draft
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
27 changes: 26 additions & 1 deletion src/Analyser/ExpressionTypeHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PhpParser\Node\Expr;
use PHPStan\TrinaryLogic;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;

Expand Down Expand Up @@ -47,7 +48,31 @@
return false;
}

return $this->type === $other->type || $this->type->equals($other->type);
if ($this->type === $other->type) {
return true;
}

if ($this->type instanceof ObjectType && $other->type instanceof ObjectType) {

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.5)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.5)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5, ubuntu-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5, ubuntu-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.4)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.4)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, ubuntu-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, ubuntu-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5, windows-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5, windows-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, windows-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, windows-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Doing ins

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Doing ins

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Doing ins

Check failure on line 55 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Doing ins
if (!$this->type->equals($other->type)) {
return false;
}

$classReflection = $this->type->getClassReflection();
$otherClassReflection = $other->type->getClassReflection();
if (
$classReflection !== null && $otherClassReflection !== null
&& (

Check failure on line 64 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 64 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 64 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 64 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.
$classReflection->hasFinalByKeywordOverride()

Check failure on line 65 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 65 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 65 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, windows-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.

Check failure on line 65 in src/Analyser/ExpressionTypeHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, windows-latest)

Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.
!== $otherClassReflection->hasFinalByKeywordOverride()
)
) {
return false;
}

return true;
}

return $this->type->equals($other->type);
}

public function and(self $other): self
Expand Down
14 changes: 12 additions & 2 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -3382,9 +3382,19 @@ public function specifyExpressionType(Expr $expr, Type $type, Type $nativeType,

$exprString = $this->getNodeKey($expr);
$expressionTypes = $scope->expressionTypes;
$expressionTypes[$exprString] = new ExpressionTypeHolder($expr, $type, $certainty);
$newHolder = new ExpressionTypeHolder($expr, $type, $certainty);
$nativeTypes = $scope->nativeExpressionTypes;
$nativeTypes[$exprString] = new ExpressionTypeHolder($expr, $nativeType, $certainty);
$newNativeHolder = new ExpressionTypeHolder($expr, $nativeType, $certainty);

if (
!isset($scope->expressionTypes[$exprString])
|| !isset($scope->nativeExpressionTypes[$exprString])
|| !$newHolder->equals($scope->expressionTypes[$exprString])
|| !$newNativeHolder->equals($scope->nativeExpressionTypes[$exprString])
) {
$expressionTypes[$exprString] = $newHolder;
$nativeTypes[$exprString] = $newNativeHolder;
}

$scope = $this->scopeFactory->create(
$this->context,
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/bug-2911.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,6 @@ private function getResultSettings(array $settings): array
function foo(array $array): void {
$array['bar'] = 'string';

assertType("non-empty-array&hasOffsetValue('bar', 'string')", $array);
assertType("non-empty-array<mixed>&hasOffsetValue('bar', 'string')", $array);
}
}
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/superglobals.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function canBeOverwritten(): void
public function canBePartlyOverwritten(): void
{
$GLOBALS['foo'] = 'foo';
assertType("non-empty-array&hasOffsetValue('foo', 'foo')", $GLOBALS);
assertType("non-empty-array<mixed>&hasOffsetValue('foo', 'foo')", $GLOBALS);
assertNativeType("non-empty-array<mixed>&hasOffsetValue('foo', 'foo')", $GLOBALS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ public function testBug2911(): void
{
$this->analyse([__DIR__ . '/data/bug-2911.php'], [
[
'Parameter #1 $array of function Bug2911\bar expects array{bar: string}, non-empty-array given.',
'Parameter #1 $array of function Bug2911\bar expects array{bar: string}, non-empty-array<mixed> given.',
23,
],
]);
Expand Down
Loading