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 a6dbce9

Browse files
committed
fix types
1 parent 8db02be commit a6dbce9

File tree

13 files changed

+107
-21
lines changed

13 files changed

+107
-21
lines changed

‎src/Reflection/InitializerExprTypeResolver.php‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,11 +1345,6 @@ public function resolveEqualType(Type $leftType, Type $rightType): BooleanType
13451345
return new ConstantBooleanType($leftType->getValue() == []); // phpcs:ignore
13461346
}
13471347

1348-
if ($leftType instanceof ConstantScalarType && $rightType instanceof ConstantScalarType) {
1349-
// @phpstan-ignore-next-line
1350-
return new ConstantBooleanType($leftType->getValue() == $rightType->getValue()); // phpcs:ignore
1351-
}
1352-
13531348
if ($leftType instanceof ConstantArrayType && $rightType instanceof ConstantArrayType) {
13541349
return $this->resolveConstantArrayTypeComparison($leftType, $rightType, fn ($leftValueType, $rightValueType): BooleanType => $this->resolveEqualType($leftValueType, $rightValueType));
13551350
}

‎src/Type/Accessory/HasOffsetType.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ public function isScalar(): TrinaryLogic
262262

263263
public function looseCompare(Type $type): BooleanType
264264
{
265-
return new BooleanType();
265+
return $type->isOffsetAccessible()
266+
->and($type->hasOffsetValueType($this->offsetType))->toBooleanType();
266267
}
267268

268269
public function getKeysArray(): Type

‎src/Type/ArrayType.php‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,25 @@ public function isScalar(): TrinaryLogic
347347

348348
public function looseCompare(Type $type): BooleanType
349349
{
350-
return $type->isArray()->toBooleanType();
350+
$looseTrue = new ConstantBooleanType(true);
351+
352+
if ($looseTrue->isSuperTypeOf($type)->yes()) {
353+
return new ConstantBooleanType(true);
354+
}
355+
356+
$looseFalse = new UnionType([
357+
new ObjectWithoutClassType(),
358+
new ConstantBooleanType(false),
359+
new StringType(),
360+
new NullType(),
361+
new IntegerType()
362+
]);
363+
364+
if ($looseFalse->isSuperTypeOf($type)->yes()) {
365+
return new ConstantBooleanType(false);
366+
}
367+
368+
return new BooleanType();
351369
}
352370

353371
public function isOffsetAccessible(): TrinaryLogic

‎src/Type/BooleanType.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ public function isScalar(): TrinaryLogic
120120

121121
public function looseCompare(Type $type): BooleanType
122122
{
123-
return $type->isBoolean()->toBooleanType();
123+
if ($type->isObject()->yes()) {
124+
return new ConstantBooleanType(false);
125+
}
126+
127+
return new BooleanType();
124128
}
125129

126130
public function tryRemove(Type $typeToRemove): ?Type

‎src/Type/CallableType.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPStan\Reflection\ParametersAcceptor;
1010
use PHPStan\ShouldNotHappenException;
1111
use PHPStan\TrinaryLogic;
12+
use PHPStan\Type\Constant\ConstantBooleanType;
1213
use PHPStan\Type\Generic\TemplateType;
1314
use PHPStan\Type\Generic\TemplateTypeHelper;
1415
use PHPStan\Type\Generic\TemplateTypeMap;
@@ -414,7 +415,11 @@ public function isScalar(): TrinaryLogic
414415

415416
public function looseCompare(Type $type): BooleanType
416417
{
417-
return $type->isCallable()->toBooleanType();
418+
if ($type->isObject()->yes()) {
419+
return new ConstantBooleanType(false);
420+
}
421+
422+
return new BooleanType();
418423
}
419424

420425
public function getEnumCases(): array

‎src/Type/ClassStringType.php‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ public function isSuperTypeOf(Type $type): TrinaryLogic
4242
return $type->isClassStringType();
4343
}
4444

45-
public function looseCompare(Type $type): BooleanType
46-
{
47-
return $type->isClassStringType()->toBooleanType();
48-
}
49-
5045
public function isString(): TrinaryLogic
5146
{
5247
return TrinaryLogic::createYes();

‎src/Type/Constant/ConstantArrayType.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,11 @@ public function isSuperTypeOf(Type $type): TrinaryLogic
397397

398398
public function looseCompare(Type $type): BooleanType
399399
{
400-
return $type->isConstantArray()->toBooleanType();
400+
if ($type->isObject()->yes()) {
401+
return new ConstantBooleanType(false);
402+
}
403+
404+
return new BooleanType();
401405
}
402406

403407
public function equals(Type $type): bool

‎src/Type/FloatType.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPStan\TrinaryLogic;
66
use PHPStan\Type\Accessory\AccessoryNumericStringType;
77
use PHPStan\Type\Constant\ConstantArrayType;
8+
use PHPStan\Type\Constant\ConstantBooleanType;
89
use PHPStan\Type\Constant\ConstantIntegerType;
910
use PHPStan\Type\Traits\NonArrayTypeTrait;
1011
use PHPStan\Type\Traits\NonCallableTypeTrait;
@@ -208,7 +209,11 @@ public function isScalar(): TrinaryLogic
208209

209210
public function looseCompare(Type $type): BooleanType
210211
{
211-
return $type->isFloat()->toBooleanType();
212+
if ($type->isObject()->yes()) {
213+
return new ConstantBooleanType(false);
214+
}
215+
216+
return new BooleanType();
212217
}
213218

214219
public function traverse(callable $cb): Type

‎src/Type/IntegerType.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPStan\TrinaryLogic;
66
use PHPStan\Type\Accessory\AccessoryNumericStringType;
77
use PHPStan\Type\Constant\ConstantArrayType;
8+
use PHPStan\Type\Constant\ConstantBooleanType;
89
use PHPStan\Type\Constant\ConstantIntegerType;
910
use PHPStan\Type\Traits\NonArrayTypeTrait;
1011
use PHPStan\Type\Traits\NonCallableTypeTrait;
@@ -130,7 +131,11 @@ public function isScalar(): TrinaryLogic
130131

131132
public function looseCompare(Type $type): BooleanType
132133
{
133-
return $type->isInteger()->toBooleanType();
134+
if ($type->isObject()->yes()) {
135+
return new ConstantBooleanType(false);
136+
}
137+
138+
return new BooleanType();
134139
}
135140

136141
public function tryRemove(Type $typeToRemove): ?Type

‎src/Type/IterableType.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPStan\Type;
44

55
use PHPStan\TrinaryLogic;
6+
use PHPStan\Type\Constant\ConstantBooleanType;
67
use PHPStan\Type\Generic\GenericObjectType;
78
use PHPStan\Type\Generic\TemplateMixedType;
89
use PHPStan\Type\Generic\TemplateType;
@@ -352,7 +353,11 @@ public function isScalar(): TrinaryLogic
352353

353354
public function looseCompare(Type $type): BooleanType
354355
{
355-
return $type->isIterable()->toBooleanType();
356+
if ($type->isObject()->yes()) {
357+
return new ConstantBooleanType(false);
358+
}
359+
360+
return new BooleanType();
356361
}
357362

358363
public function getEnumCases(): array

0 commit comments

Comments
(0)

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