Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/Type/Php/LtrimFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
} elseif ($trimConstantString->getValue() === '\\' && $string->isClassString()->yes()) {
$result[] = new ClassStringType();
} elseif (preg_match('/\d/', $trimConstantString->getValue()) === 0 && $string->isNumericString()->yes()) {
$result[] = new AccessoryNumericStringType();
$result[] = new IntersectionType([new StringType(), new AccessoryNumericStringType()]);
} else {
return $defaultType;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Php/TrimFunctionDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getTypeFromFunctionCall(
);
}
} elseif (preg_match('/\d/', $trimConstantString->getValue()) === 0 && $stringType->isNumericString()->yes()) {
$result[] = new AccessoryNumericStringType();
$result[] = new IntersectionType([new StringType(), new AccessoryNumericStringType()]);
} else {
return $defaultType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,11 @@ public function testBug11863(): void
$this->analyse([__DIR__ . '/data/bug-11863.php'], []);
}

public function testBug13784(): void
{
$this->analyse([__DIR__ . '/data/bug-13784.php'], []);
}

public function testBug13556(): void
{
$this->checkExplicitMixed = true;
Expand Down
22 changes: 22 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-13784.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

namespace Bug13784;

function ok(): int {
return strlen(number_format(15, 0, '', ''));
}

/**
* @param numeric-string $str
*/
function ok2(string $str): int {
return strlen($str);
}

function fail(): int {
return strlen(ltrim(number_format(15, 0, '', ''), '-'));
}

function fail2(): int {
return strlen(trim(number_format(15, 0, '', ''), '-'));
}
Loading