File tree Expand file tree Collapse file tree 4 files changed +30
-13
lines changed
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree 4 files changed +30
-13
lines changed Original file line number Diff line number Diff line change @@ -1314,15 +1314,19 @@ private function specifyTypesForConstantStringBinaryExpression(
1314
1314
&& isset ($ exprNode ->getArgs ()[0 ])
1315
1315
&& $ constantStringValue === ''
1316
1316
) {
1317
- return $ this ->create (
1318
- $ exprNode ->getArgs ()[0 ]->value ,
1319
- TypeCombinator::intersect (
1320
- new StringType (),
1321
- new AccessoryNonEmptyStringType (),
1322
- ),
1323
- $ context ->negate (),
1324
- $ scope ,
1325
- )->setRootExpr ($ rootExpr );
1317
+ $ argValue = $ exprNode ->getArgs ()[0 ]->value ;
1318
+ $ argType = $ scope ->getType ($ argValue );
1319
+ if ($ argType ->isString ()->yes ()) {
1320
+ return $ this ->create (
1321
+ $ argValue ,
1322
+ TypeCombinator::intersect (
1323
+ new StringType (),
1324
+ new AccessoryNonEmptyStringType (),
1325
+ ),
1326
+ $ context ->negate (),
1327
+ $ scope ,
1328
+ )->setRootExpr ($ rootExpr );
1329
+ }
1326
1330
}
1327
1331
1328
1332
return null ;
Original file line number Diff line number Diff line change @@ -9,21 +9,21 @@ function mbtrim($value): void
9
9
if (mb_trim ($ value ) === '' ) {
10
10
assertType ('mixed ' , $ value );
11
11
} else {
12
- assertType ('non-empty-string ' , $ value );
12
+ assertType ('mixed ' , $ value );
13
13
}
14
14
assertType ('mixed ' , $ value );
15
15
16
16
if (mb_ltrim ($ value ) === '' ) {
17
17
assertType ('mixed ' , $ value );
18
18
} else {
19
- assertType ('non-empty-string ' , $ value );
19
+ assertType ('mixed ' , $ value );
20
20
}
21
21
assertType ('mixed ' , $ value );
22
22
23
23
if (mb_rtrim ($ value ) === '' ) {
24
24
assertType ('mixed ' , $ value );
25
25
} else {
26
- assertType ('non-empty-string ' , $ value );
26
+ assertType ('mixed ' , $ value );
27
27
}
28
28
assertType ('mixed ' , $ value );
29
29
}
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ function trimMixed($value): void
21
21
if (trim ($ value ) === '' ) {
22
22
assertType ('mixed ' , $ value );
23
23
} else {
24
- assertType ('non-empty-string ' , $ value );
24
+ assertType ('mixed ' , $ value );
25
25
}
26
26
assertType ('mixed ' , $ value );
27
27
Original file line number Diff line number Diff line change
1
+ <?php // lint >= 8.0
2
+
3
+ namespace Bug13552 ;
4
+
5
+ use function PHPStan \Testing \assertType ;
6
+
7
+ function doSomething (mixed $ value ): void
8
+ {
9
+ if (trim ($ value ) === '' ) {
10
+ return ;
11
+ }
12
+ assertType ('mixed ' , $ value );
13
+ }
You can’t perform that action at this time.
0 commit comments