Skip to content

Commit

Permalink
simplify TypeSpecifierComparisonContext
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jun 25, 2024
1 parent 22ea0a9 commit 40bb131
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
9 changes: 5 additions & 4 deletions src/Analyser/TypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -1883,18 +1883,17 @@ private function specifyWithComparisonAwareTypeSpecifyingExtensions(
if (!$this->reflectionProvider->hasFunction($callLike->name, $scope)) {
return null;
}
$functionReflection = $this->reflectionProvider->getFunction($callLike->name, $scope);

$comparisonContext = TypeSpecifierContext::createComparison(
new TypeSpecifierComparisonContext(
$binaryOp,
$callExpr,
$callLike,
$comparisonType,
$context,
$rootExpr,
),
);
$functionReflection = $this->reflectionProvider->getFunction($callLike->name, $scope);
foreach ($this->getFunctionTypeSpecifyingExtensions() as $extension) {
if (!$extension instanceof ComparisonAwareTypeSpecifyingExtension) {
continue;
Expand Down Expand Up @@ -1946,7 +1945,8 @@ public function resolveEqual(Expr\BinaryOp\Equal $expr, Scope $scope, TypeSpecif
}

if (
$exprNode instanceof Expr\CallLike
$context->true()
&& $exprNode instanceof Expr\CallLike
) {
$specifiedTypes = $this->specifyWithComparisonAwareTypeSpecifyingExtensions(
$expr,
Expand Down Expand Up @@ -2051,7 +2051,8 @@ public function resolveIdentical(Expr\BinaryOp\Identical $expr, Scope $scope, Ty
$rightType = $scope->getType($rightExpr);

if (
$unwrappedLeftExpr instanceof FuncCall
$context->true()
&& $unwrappedLeftExpr instanceof FuncCall
&& $unwrappedLeftExpr->name instanceof Name
) {
$specifiedTypes = $this->specifyWithComparisonAwareTypeSpecifyingExtensions(
Expand Down
7 changes: 0 additions & 7 deletions src/Analyser/TypeSpecifierComparisonContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\CallLike;
use PHPStan\Type\Type;

/** @api */
Expand All @@ -14,7 +13,6 @@ final class TypeSpecifierComparisonContext
public function __construct(
private BinaryOp $binaryOp,
private Expr $callExpr,
private CallLike $callLike,
private Type $comparisonType,
private TypeSpecifierContext $context,
private ?Expr $rootExpr,
Expand All @@ -32,11 +30,6 @@ public function getCallExpr(): Expr
return $this->callExpr;
}

public function getCallLike(): CallLike
{
return $this->callLike;
}

public function getComparisonType(): Type
{
return $this->comparisonType;
Expand Down
1 change: 0 additions & 1 deletion tests/PHPStan/Analyser/TypeSpecifierContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ private function createComparisonContext(): TypeSpecifierContext
new TypeSpecifierComparisonContext(
new Equal(new String_('dummy'), new String_('dummy2')),
new FuncCall('dummyFunc'),

Check failure on line 123 in tests/PHPStan/Analyser/TypeSpecifierContextTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

Parameter #1 $name of class PhpParser\Node\Expr\FuncCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Name, string given.

Check failure on line 123 in tests/PHPStan/Analyser/TypeSpecifierContextTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Parameter #1 $name of class PhpParser\Node\Expr\FuncCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Name, string given.

Check failure on line 123 in tests/PHPStan/Analyser/TypeSpecifierContextTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Parameter #1 $name of class PhpParser\Node\Expr\FuncCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Name, string given.

Check failure on line 123 in tests/PHPStan/Analyser/TypeSpecifierContextTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Parameter #1 $name of class PhpParser\Node\Expr\FuncCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Name, string given.

Check failure on line 123 in tests/PHPStan/Analyser/TypeSpecifierContextTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Parameter #1 $name of class PhpParser\Node\Expr\FuncCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Name, string given.

Check failure on line 123 in tests/PHPStan/Analyser/TypeSpecifierContextTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Parameter #1 $name of class PhpParser\Node\Expr\FuncCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Name, string given.

Check failure on line 123 in tests/PHPStan/Analyser/TypeSpecifierContextTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Parameter #1 $name of class PhpParser\Node\Expr\FuncCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Name, string given.

Check failure on line 123 in tests/PHPStan/Analyser/TypeSpecifierContextTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Parameter #1 $name of class PhpParser\Node\Expr\FuncCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Name, string given.

Check failure on line 123 in tests/PHPStan/Analyser/TypeSpecifierContextTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, ubuntu-latest)

Parameter #1 $name of class PhpParser\Node\Expr\FuncCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Name, string given.

Check failure on line 123 in tests/PHPStan/Analyser/TypeSpecifierContextTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Parameter #1 $name of class PhpParser\Node\Expr\FuncCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Name, string given.

Check failure on line 123 in tests/PHPStan/Analyser/TypeSpecifierContextTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Parameter #1 $name of class PhpParser\Node\Expr\FuncCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Name, string given.

Check failure on line 123 in tests/PHPStan/Analyser/TypeSpecifierContextTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Parameter #1 $name of class PhpParser\Node\Expr\FuncCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Name, string given.

Check failure on line 123 in tests/PHPStan/Analyser/TypeSpecifierContextTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Parameter #1 $name of class PhpParser\Node\Expr\FuncCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Name, string given.

Check failure on line 123 in tests/PHPStan/Analyser/TypeSpecifierContextTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, windows-latest)

Parameter #1 $name of class PhpParser\Node\Expr\FuncCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Name, string given.

Check failure on line 123 in tests/PHPStan/Analyser/TypeSpecifierContextTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, windows-latest)

Parameter #1 $name of class PhpParser\Node\Expr\FuncCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Name, string given.
new FuncCall('dummyFunc'),
new NullType(),
TypeSpecifierContext::createNull(),
null,
Expand Down

0 comments on commit 40bb131

Please sign in to comment.