🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

Commit c128b84

Browse files
ondrejmirtesclaude
andcommitted
Extract EqualityTypeSpecifyingHelper from TypeSpecifier
resolveEqual and resolveIdentical (plus their private helpers resolveNormalizedIdentical, findTypeExpressionsFromBinaryOperation, specifyTypesForConstantBinaryExpression and specifyTypesForConstantStringBinaryExpression) were only used by BinaryOpHandler. Move them into a new AutowiredService EqualityTypeSpecifyingHelper and rename the entry points to specifyTypesForEqual()/specifyTypesForIdentical() to signal they only produce SpecifiedTypes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 3a70970 commit c128b84

4 files changed

Lines changed: 969 additions & 913 deletions

File tree

phpstan-baseline.neon

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ parameters:
4242
count: 1
4343
path: src/Analyser/ExprHandler/BooleanNotHandler.php
4444

45+
-
46+
rawMessage: 'Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.'
47+
identifier: phpstanApi.instanceofType
48+
count: 2
49+
path: src/Analyser/ExprHandler/Helper/EqualityTypeSpecifyingHelper.php
50+
51+
-
52+
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantBooleanType is error-prone and deprecated. Use Type::isTrue() or Type::isFalse() instead.'
53+
identifier: phpstanApi.instanceofType
54+
count: 3
55+
path: src/Analyser/ExprHandler/Helper/EqualityTypeSpecifyingHelper.php
56+
4557
-
4658
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.'
4759
identifier: phpstanApi.instanceofType
@@ -102,16 +114,10 @@ parameters:
102114
count: 1
103115
path: src/Analyser/RuleErrorTransformer.php
104116

105-
-
106-
rawMessage: 'Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.'
107-
identifier: phpstanApi.instanceofType
108-
count: 2
109-
path: src/Analyser/TypeSpecifier.php
110-
111117
-
112118
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantBooleanType is error-prone and deprecated. Use Type::isTrue() or Type::isFalse() instead.'
113119
identifier: phpstanApi.instanceofType
114-
count: 5
120+
count: 2
115121
path: src/Analyser/TypeSpecifier.php
116122

117123
-

src/Analyser/ExprHandler/BinaryOpHandler.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PHPStan\Analyser\ExpressionResult;
1717
use PHPStan\Analyser\ExpressionResultStorage;
1818
use PHPStan\Analyser\ExprHandler;
19+
use PHPStan\Analyser\ExprHandler\Helper\EqualityTypeSpecifyingHelper;
1920
use PHPStan\Analyser\ExprHandler\Helper\ImplicitToStringCallHelper;
2021
use PHPStan\Analyser\InternalThrowPoint;
2122
use PHPStan\Analyser\MutatingScope;
@@ -64,6 +65,7 @@ public function __construct(
6465
private PhpVersion $phpVersion,
6566
private ImplicitToStringCallHelper $implicitToStringCallHelper,
6667
private ExprPrinter $exprPrinter,
68+
private EqualityTypeSpecifyingHelper $equalityTypeSpecifyingHelper,
6769
)
6870
{
6971
}
@@ -233,7 +235,7 @@ public function resolveType(MutatingScope $scope, Expr $expr): Type
233235
public function specifyTypes(TypeSpecifier $typeSpecifier, Scope $scope, Expr $expr, TypeSpecifierContext $context): SpecifiedTypes
234236
{
235237
if ($expr instanceof BinaryOp\Identical) {
236-
return $typeSpecifier->resolveIdentical($expr, $scope, $context);
238+
return $this->equalityTypeSpecifyingHelper->specifyTypesForIdentical($expr, $scope, $context);
237239
}
238240

239241
if ($expr instanceof BinaryOp\NotIdentical) {
@@ -245,7 +247,7 @@ public function specifyTypes(TypeSpecifier $typeSpecifier, Scope $scope, Expr $e
245247
}
246248

247249
if ($expr instanceof BinaryOp\Equal) {
248-
return $typeSpecifier->resolveEqual($expr, $scope, $context);
250+
return $this->equalityTypeSpecifyingHelper->specifyTypesForEqual($expr, $scope, $context);
249251
}
250252

251253
if ($expr instanceof BinaryOp\NotEqual) {

0 commit comments

Comments
 (0)