Skip to content

Commit b551de8

Browse files
committed
add partially broken test for bcmath operator type
1 parent e8d0051 commit b551de8

File tree

4 files changed

+483
-465
lines changed

4 files changed

+483
-465
lines changed

src/Type/ObjectType.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
use PHPStan\Reflection\Type\UnresolvedPropertyPrototypeReflection;
3232
use PHPStan\ShouldNotHappenException;
3333
use PHPStan\TrinaryLogic;
34+
use PHPStan\Type\Accessory\AccessoryNonEmptyStringType;
35+
use PHPStan\Type\Accessory\AccessoryNumericStringType;
3436
use PHPStan\Type\Constant\ConstantArrayType;
3537
use PHPStan\Type\Constant\ConstantBooleanType;
3638
use PHPStan\Type\Constant\ConstantStringType;
@@ -593,6 +595,14 @@ public function toFloat(): Type
593595

594596
public function toString(): Type
595597
{
598+
if ($this->isInstanceOf('BcMath\Number')->yes()) {
599+
return new IntersectionType([
600+
new StringType(),
601+
new AccessoryNumericStringType(),
602+
new AccessoryNonEmptyStringType(),
603+
]);
604+
}
605+
596606
$classReflection = $this->getClassReflection();
597607
if ($classReflection === null) {
598608
return new ErrorType();
@@ -673,7 +683,10 @@ public function toArrayKey(): Type
673683

674684
public function toBoolean(): BooleanType
675685
{
676-
if ($this->isInstanceOf('SimpleXMLElement')->yes()) {
686+
if (
687+
$this->isInstanceOf('SimpleXMLElement')->yes()
688+
|| $this->isInstanceOf('BcMath\Number')->yes()
689+
) {
677690
return new BooleanType();
678691
}
679692

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ private static function findTestFiles(): iterable
195195
yield __DIR__ . '/../Rules/Comparison/data/bug-9499.php';
196196
}
197197

198+
if (PHP_VERSION_ID >= 80400) {
199+
yield __DIR__ . '/../Rules/Operators/data/bcmath-number.php';
200+
}
201+
198202
yield __DIR__ . '/../Rules/PhpDoc/data/bug-8609-function.php';
199203
yield __DIR__ . '/../Rules/Comparison/data/bug-5365.php';
200204
yield __DIR__ . '/../Rules/Comparison/data/bug-6551.php';

0 commit comments

Comments
 (0)