Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5cb9f5a

Browse files
committed
Implement Type->looseCompare(type)
1 parent e5c1a59 commit 5cb9f5a

35 files changed

+199
-1
lines changed

‎src/Reflection/InitializerExprTypeResolver.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ public function resolveEqualType(Type $leftType, Type $rightType): BooleanType
13541354
return $this->resolveConstantArrayTypeComparison($leftType, $rightType, fn ($leftValueType, $rightValueType): BooleanType => $this->resolveEqualType($leftValueType, $rightValueType));
13551355
}
13561356

1357-
return newBooleanType();
1357+
return $leftType->looseCompare($rightType);
13581358
}
13591359

13601360
/**

‎src/Type/Accessory/AccessoryArrayListType.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPStan\TrinaryLogic;
66
use PHPStan\Type\AcceptsResult;
7+
use PHPStan\Type\BooleanType;
78
use PHPStan\Type\CompoundType;
89
use PHPStan\Type\Constant\ConstantFloatType;
910
use PHPStan\Type\Constant\ConstantIntegerType;
@@ -355,6 +356,11 @@ public function isScalar(): TrinaryLogic
355356
return TrinaryLogic::createNo();
356357
}
357358

359+
public function looseCompare(Type $type): BooleanType
360+
{
361+
return $type->isList()->toBooleanType();
362+
}
363+
358364
public function toNumber(): Type
359365
{
360366
return new ErrorType();

‎src/Type/Accessory/AccessoryLiteralStringType.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ public function isScalar(): TrinaryLogic
263263
return TrinaryLogic::createYes();
264264
}
265265

266+
public function looseCompare(Type $type): BooleanType
267+
{
268+
return $type->isLiteralString()->toBooleanType();
269+
}
270+
266271
public function traverse(callable $cb): Type
267272
{
268273
return $this;

‎src/Type/Accessory/AccessoryNonEmptyStringType.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPStan\TrinaryLogic;
66
use PHPStan\Type\AcceptsResult;
77
use PHPStan\Type\BenevolentUnionType;
8+
use PHPStan\Type\BooleanType;
89
use PHPStan\Type\CompoundType;
910
use PHPStan\Type\Constant\ConstantArrayType;
1011
use PHPStan\Type\Constant\ConstantIntegerType;
@@ -258,6 +259,11 @@ public function isScalar(): TrinaryLogic
258259
return TrinaryLogic::createYes();
259260
}
260261

262+
public function looseCompare(Type $type): BooleanType
263+
{
264+
return $type->isNonEmptyString()->toBooleanType();
265+
}
266+
261267
public function traverse(callable $cb): Type
262268
{
263269
return $this;

‎src/Type/Accessory/AccessoryNonFalsyStringType.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPStan\TrinaryLogic;
66
use PHPStan\Type\AcceptsResult;
77
use PHPStan\Type\BenevolentUnionType;
8+
use PHPStan\Type\BooleanType;
89
use PHPStan\Type\CompoundType;
910
use PHPStan\Type\Constant\ConstantArrayType;
1011
use PHPStan\Type\Constant\ConstantIntegerType;
@@ -258,6 +259,11 @@ public function isScalar(): TrinaryLogic
258259
return TrinaryLogic::createYes();
259260
}
260261

262+
public function looseCompare(Type $type): BooleanType
263+
{
264+
return $type->isNonFalsyString()->toBooleanType();
265+
}
266+
261267
public function traverse(callable $cb): Type
262268
{
263269
return $this;

‎src/Type/Accessory/AccessoryNumericStringType.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPStan\TrinaryLogic;
66
use PHPStan\Type\AcceptsResult;
77
use PHPStan\Type\BenevolentUnionType;
8+
use PHPStan\Type\BooleanType;
89
use PHPStan\Type\CompoundType;
910
use PHPStan\Type\Constant\ConstantArrayType;
1011
use PHPStan\Type\Constant\ConstantIntegerType;
@@ -261,6 +262,11 @@ public function isScalar(): TrinaryLogic
261262
return TrinaryLogic::createYes();
262263
}
263264

265+
public function looseCompare(Type $type): BooleanType
266+
{
267+
return $type->isNumericString()->toBooleanType();
268+
}
269+
264270
public function traverse(callable $cb): Type
265271
{
266272
return $this;

‎src/Type/Accessory/HasOffsetType.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPStan\TrinaryLogic;
66
use PHPStan\Type\AcceptsResult;
7+
use PHPStan\Type\BooleanType;
78
use PHPStan\Type\CompoundType;
89
use PHPStan\Type\Constant\ConstantIntegerType;
910
use PHPStan\Type\Constant\ConstantStringType;
@@ -259,6 +260,11 @@ public function isScalar(): TrinaryLogic
259260
return TrinaryLogic::createMaybe();
260261
}
261262

263+
public function looseCompare(Type $type): BooleanType
264+
{
265+
return new BooleanType();
266+
}
267+
262268
public function getKeysArray(): Type
263269
{
264270
return new NonEmptyArrayType();

‎src/Type/Accessory/HasOffsetValueType.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPStan\ShouldNotHappenException;
66
use PHPStan\TrinaryLogic;
77
use PHPStan\Type\AcceptsResult;
8+
use PHPStan\Type\BooleanType;
89
use PHPStan\Type\CompoundType;
910
use PHPStan\Type\Constant\ConstantIntegerType;
1011
use PHPStan\Type\Constant\ConstantStringType;
@@ -314,6 +315,11 @@ public function isScalar(): TrinaryLogic
314315
return TrinaryLogic::createMaybe();
315316
}
316317

318+
public function looseCompare(Type $type): BooleanType
319+
{
320+
return $type->hasOffsetValueType($this->offsetType)->toBooleanType();
321+
}
322+
317323
public function toNumber(): Type
318324
{
319325
return new ErrorType();

‎src/Type/Accessory/NonEmptyArrayType.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPStan\TrinaryLogic;
66
use PHPStan\Type\AcceptsResult;
7+
use PHPStan\Type\BooleanType;
78
use PHPStan\Type\CompoundType;
89
use PHPStan\Type\Constant\ConstantFloatType;
910
use PHPStan\Type\Constant\ConstantIntegerType;
@@ -340,6 +341,11 @@ public function isScalar(): TrinaryLogic
340341
return TrinaryLogic::createNo();
341342
}
342343

344+
public function looseCompare(Type $type): BooleanType
345+
{
346+
return $type->isArray()->and($type->isIterableAtLeastOnce())->toBooleanType();
347+
}
348+
343349
public function toNumber(): Type
344350
{
345351
return new ErrorType();

‎src/Type/Accessory/OversizedArrayType.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPStan\TrinaryLogic;
66
use PHPStan\Type\AcceptsResult;
7+
use PHPStan\Type\BooleanType;
78
use PHPStan\Type\CompoundType;
89
use PHPStan\Type\Constant\ConstantFloatType;
910
use PHPStan\Type\Constant\ConstantIntegerType;
@@ -326,6 +327,11 @@ public function isScalar(): TrinaryLogic
326327
return TrinaryLogic::createNo();
327328
}
328329

330+
public function looseCompare(Type $type): BooleanType
331+
{
332+
return $type->isOversizedArray()->toBooleanType();
333+
}
334+
329335
public function toNumber(): Type
330336
{
331337
return new ErrorType();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /