Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/Type/Php/CtypeDigitFunctionTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use PHPStan\DependencyInjection\AutowiredService;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\Accessory\AccessoryDecimalIntegerStringType;
use PHPStan\Type\Accessory\AccessoryNumericStringType;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\FunctionTypeSpecifyingExtension;
Expand Down Expand Up @@ -57,7 +56,7 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
if ($context->true()) {
$types[] = new IntersectionType([
new StringType(),
new AccessoryDecimalIntegerStringType(),
new AccessoryNumericStringType(),
]);
}

Expand All @@ -69,9 +68,6 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
new StringType(),
new AccessoryNumericStringType(),
];
if ($context->true()) {
$accessories[] = new AccessoryDecimalIntegerStringType();
}
$castedType = new UnionType([
IntegerRangeType::fromInterval(0, null),
new IntersectionType($accessories),
Expand Down
18 changes: 18 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-14792.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);

namespace Bug14792;

use function PHPStan\Testing\assertType;

function test(string $x): bool
{
if (ctype_digit($x)) {
// '02' passes ctype_digit() but is not a decimal-int-string,
// so $x must not be narrowed to decimal-int-string.
assertType('numeric-string', $x);
if ($x === '02') { // absolutely possible
return true;
}
}
return false;
}
4 changes: 2 additions & 2 deletions tests/PHPStan/Analyser/nsrt/callsite-cast-narrowing.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class HelloWorld
public function sayHello($mixed, int $int, string $string, $numericString, $nonEmptyString, bool $bool): void
{
if (ctype_digit((string) $mixed)) {
assertType('int<0, max>|decimal-int-string|true', $mixed);
assertType('int<0, max>|numeric-string|true', $mixed);
} else {
assertType('mixed~(int<0, max>|numeric-string|true)', $mixed);
}
Expand Down Expand Up @@ -41,7 +41,7 @@ public function sayHello($mixed, int $int, string $string, $numericString, $nonE
assertType('int', $int);

if (ctype_digit((string) $string)) {
assertType('decimal-int-string', $string);
assertType('numeric-string', $string);
} else {
assertType('string', $string);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/PHPStan/Analyser/nsrt/ctype-digit.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function foo(mixed $foo): void
assertType('mixed', $foo);

if (is_string($foo) && ctype_digit($foo)) {
assertType('decimal-int-string', $foo);
assertType('numeric-string', $foo);
} else {
assertType('mixed', $foo);
}
Expand All @@ -26,7 +26,7 @@ public function foo(mixed $foo): void
}

if (ctype_digit($foo)) {
assertType('int<48, 57>|int<256, max>|decimal-int-string', $foo);
assertType('int<48, 57>|int<256, max>|numeric-string', $foo);
return;
}

Expand All @@ -36,7 +36,7 @@ public function foo(mixed $foo): void
public function doString(string $string): void
{
if (ctype_digit($string) === true) {
assertType('decimal-int-string', $string);
assertType('numeric-string', $string);
} else {
assertType('string', $string);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1328,12 +1328,7 @@ public function testBug9240(): void

public function testBug14758(): void
{
$this->analyse([__DIR__ . '/data/bug-14758.php'], [
[
'Offset decimal-int-string does not exist on array<string, string>.',
11,
],
]);
$this->analyse([__DIR__ . '/data/bug-14758.php'], []);
}

#[RequiresPhp('>= 8.4.0')]
Expand Down
Loading