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 9b9a23e

Browse files
committed
fix
1 parent 23ec354 commit 9b9a23e

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

‎src/Type/Php/StrlenTypeSpecifyingExtension.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPStan\Type\Constant\ConstantIntegerType;
1515
use PHPStan\Type\FunctionTypeSpecifyingExtension;
1616
use PHPStan\Type\IntegerRangeType;
17+
use PHPStan\Type\NeverType;
1718
use function count;
1819
use function in_array;
1920
use function strtolower;
@@ -49,6 +50,10 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
4950
}
5051

5152
$returnType = $context->getReturnType();
53+
if ($returnType instanceof NeverType) {
54+
return $this->typeSpecifier->create($args[0]->value, $returnType, $context->negate(), $scope);
55+
}
56+
5257
if (
5358
$context->true() && IntegerRangeType::createAllGreaterThanOrEqualTo(1)->isSuperTypeOf($returnType)->yes()
5459
|| ($context->false() && (new ConstantIntegerType(0))->isSuperTypeOf($returnType)->yes())
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace StrlenNever;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @param non-empty-string $nonES
9+
* @param non-falsy-string $nonFalsy
10+
* @param numeric-string $numericString
11+
* @param lowercase-string $lower
12+
* @param uppercase-string $upper
13+
*/
14+
function doFoo(string $s, $nonES, $nonFalsy, $numericString, $lower, $upper) {
15+
if (strlen($s) <= 0) {
16+
assertType("''", $s);
17+
}
18+
if (strlen($nonES) <= 0) {
19+
assertType('*NEVER*', $nonES);
20+
}
21+
if (strlen($nonFalsy) <= 0) {
22+
assertType('*NEVER*', $nonFalsy);
23+
}
24+
if (strlen($numericString) <= 0) {
25+
assertType("*NEVER*", $numericString);
26+
}
27+
if (strlen($lower) <= 0) {
28+
assertType("''", $lower);
29+
}
30+
if (strlen($upper) <= 0) {
31+
assertType("''", $upper);
32+
}
33+
}
34+
35+
36+
function doBar(string $m): void
37+
{
38+
if (strlen($m) >= 1) {
39+
if (strlen($m) <= 0) {
40+
assertType('*NEVER*', $m);
41+
}
42+
}
43+
}
44+

0 commit comments

Comments
(0)

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