Skip to content

Commit bde2066

Browse files
phpstan-botclaude
authored andcommitted
Rename shouldNotDetermineCheckResult to specifyOnly
The flag means "these SpecifiedTypes only narrow types, don't use them to determine check outcome" — `specifyOnly` captures this concisely using the domain language of the SpecifiedTypes class. `overwrite` remains independent: it controls how types are applied in MutatingScope (assign vs intersect), while `specifyOnly` controls ImpossibleCheckTypeHelper. They already have separate early-return checks and serve different purposes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5cbed3a commit bde2066

5 files changed

Lines changed: 23 additions & 27 deletions

File tree

src/Analyser/SpecifiedTypes.php

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final class SpecifiedTypes
1313

1414
private bool $overwrite = false;
1515

16-
private bool $shouldNotDetermineCheckResult = false;
16+
private bool $specifyOnly = false;
1717

1818
/** @var array<string, ConditionalExpressionHolder[]> */
1919
private array $newConditionalExpressionHolders = [];
@@ -53,29 +53,28 @@ public function setAlwaysOverwriteTypes(): self
5353
{
5454
$self = new self($this->sureTypes, $this->sureNotTypes);
5555
$self->overwrite = true;
56-
$self->shouldNotDetermineCheckResult = $this->shouldNotDetermineCheckResult;
56+
$self->specifyOnly = $this->specifyOnly;
5757
$self->newConditionalExpressionHolders = $this->newConditionalExpressionHolders;
5858
$self->rootExpr = $this->rootExpr;
5959

6060
return $self;
6161
}
6262

6363
/**
64-
* Normally, when a type-specifying extension returns SpecifiedTypes with sureTypes,
65-
* ImpossibleCheckTypeHelper will analyze whether those types are already satisfied
66-
* and conclude the check is always-true/always-false.
64+
* When set, the sureTypes are only used for narrowing — ImpossibleCheckTypeHelper
65+
* will not use them to determine whether the check is always-true/always-false.
6766
*
68-
* When this flag is set, that analysis is skipped. Use this when the sureTypes
69-
* are a side effect of the check (e.g. str_contains narrowing haystack to non-empty-string)
67+
* Use this when the sureTypes are a side effect of the check
68+
* (e.g. str_contains narrowing haystack to non-empty-string)
7069
* rather than the determining condition.
7170
*
7271
* @api
7372
*/
74-
public function setShouldNotDetermineCheckResult(): self
73+
public function setSpecifyOnly(): self
7574
{
7675
$self = new self($this->sureTypes, $this->sureNotTypes);
7776
$self->overwrite = $this->overwrite;
78-
$self->shouldNotDetermineCheckResult = true;
77+
$self->specifyOnly = true;
7978
$self->newConditionalExpressionHolders = $this->newConditionalExpressionHolders;
8079
$self->rootExpr = $this->rootExpr;
8180

@@ -89,7 +88,7 @@ public function setRootExpr(?Expr $rootExpr): self
8988
{
9089
$self = new self($this->sureTypes, $this->sureNotTypes);
9190
$self->overwrite = $this->overwrite;
92-
$self->shouldNotDetermineCheckResult = $this->shouldNotDetermineCheckResult;
91+
$self->specifyOnly = $this->specifyOnly;
9392
$self->newConditionalExpressionHolders = $this->newConditionalExpressionHolders;
9493
$self->rootExpr = $rootExpr;
9594

@@ -103,7 +102,7 @@ public function setNewConditionalExpressionHolders(array $newConditionalExpressi
103102
{
104103
$self = new self($this->sureTypes, $this->sureNotTypes);
105104
$self->overwrite = $this->overwrite;
106-
$self->shouldNotDetermineCheckResult = $this->shouldNotDetermineCheckResult;
105+
$self->specifyOnly = $this->specifyOnly;
107106
$self->newConditionalExpressionHolders = $newConditionalExpressionHolders;
108107
$self->rootExpr = $this->rootExpr;
109108

@@ -133,9 +132,9 @@ public function shouldOverwrite(): bool
133132
return $this->overwrite;
134133
}
135134

136-
public function shouldNotDetermineCheckResult(): bool
135+
public function isSpecifyOnly(): bool
137136
{
138-
return $this->shouldNotDetermineCheckResult;
137+
return $this->specifyOnly;
139138
}
140139

141140
/**
@@ -160,7 +159,7 @@ public function removeExpr(string $exprString): self
160159

161160
$self = new self($sureTypes, $sureNotTypes);
162161
$self->overwrite = $this->overwrite;
163-
$self->shouldNotDetermineCheckResult = $this->shouldNotDetermineCheckResult;
162+
$self->specifyOnly = $this->specifyOnly;
164163
$self->newConditionalExpressionHolders = $this->newConditionalExpressionHolders;
165164
$self->rootExpr = $this->rootExpr;
166165

@@ -200,8 +199,8 @@ public function intersectWith(SpecifiedTypes $other): self
200199
if ($this->overwrite && $other->overwrite) {
201200
$result = $result->setAlwaysOverwriteTypes();
202201
}
203-
if ($this->shouldNotDetermineCheckResult || $other->shouldNotDetermineCheckResult) {
204-
$result = $result->setShouldNotDetermineCheckResult();
202+
if ($this->specifyOnly || $other->specifyOnly) {
203+
$result = $result->setSpecifyOnly();
205204
}
206205

207206
return $result->setRootExpr($rootExpr);
@@ -240,8 +239,8 @@ public function unionWith(SpecifiedTypes $other): self
240239
if ($this->overwrite || $other->overwrite) {
241240
$result = $result->setAlwaysOverwriteTypes();
242241
}
243-
if ($this->shouldNotDetermineCheckResult || $other->shouldNotDetermineCheckResult) {
244-
$result = $result->setShouldNotDetermineCheckResult();
242+
if ($this->specifyOnly || $other->specifyOnly) {
243+
$result = $result->setSpecifyOnly();
245244
}
246245

247246
$conditionalExpressionHolders = $this->newConditionalExpressionHolders;
@@ -274,8 +273,8 @@ public function normalize(Scope $scope): self
274273
if ($this->overwrite) {
275274
$result = $result->setAlwaysOverwriteTypes();
276275
}
277-
if ($this->shouldNotDetermineCheckResult) {
278-
$result = $result->setShouldNotDetermineCheckResult();
276+
if ($this->specifyOnly) {
277+
$result = $result->setSpecifyOnly();
279278
}
280279

281280
return $result->setRootExpr($this->rootExpr);

src/Analyser/TypeSpecifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1858,7 +1858,7 @@ static function (Type $type, callable $traverse) use ($templateTypeMap, &$contai
18581858
$scope,
18591859
)->setRootExpr($containsUnresolvedTemplate ? $call : null);
18601860
if ($assert->isEquality()) {
1861-
$newTypes = $newTypes->setShouldNotDetermineCheckResult();
1861+
$newTypes = $newTypes->setSpecifyOnly();
18621862
}
18631863
$types = $types !== null ? $types->unionWith($newTypes) : $newTypes;
18641864

src/Rules/Comparison/ImpossibleCheckTypeHelper.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,7 @@ public function findSpecifiedType(
273273
return null;
274274
}
275275

276-
// sureTypes are side effects of the check (e.g. str_contains narrowing
277-
// haystack to non-empty-string), not the determining condition — they
278-
// can't tell us whether the check is always-true or always-false.
279-
if ($specifiedTypes->shouldNotDetermineCheckResult()) {
276+
if ($specifiedTypes->isSpecifyOnly()) {
280277
return null;
281278
}
282279

src/Type/Php/ArrayKeyExistsFunctionTypeSpecifyingExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function specifyTypes(
112112
$arrayType->getIterableValueType(),
113113
$context,
114114
$scope,
115-
))->setShouldNotDetermineCheckResult();
115+
))->setSpecifyOnly();
116116
}
117117

118118
return new SpecifiedTypes();

src/Type/Php/StrContainingTypeSpecifyingExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
8484
new IntersectionType($accessories),
8585
$context,
8686
$scope,
87-
)->setShouldNotDetermineCheckResult();
87+
)->setSpecifyOnly();
8888
}
8989
}
9090

0 commit comments

Comments
 (0)