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(
13141314 && isset ($ exprNode ->getArgs ()[0 ])
13151315 && $ constantStringValue === ''
13161316 ) {
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+ }
13261330 }
13271331
13281332 return null ;
Original file line number Diff line number Diff line change @@ -9,21 +9,21 @@ function mbtrim($value): void
99 if (mb_trim ($ value ) === '' ) {
1010 assertType ('mixed ' , $ value );
1111 } else {
12- assertType ('non-empty-string ' , $ value );
12+ assertType ('mixed ' , $ value );
1313 }
1414 assertType ('mixed ' , $ value );
1515
1616 if (mb_ltrim ($ value ) === '' ) {
1717 assertType ('mixed ' , $ value );
1818 } else {
19- assertType ('non-empty-string ' , $ value );
19+ assertType ('mixed ' , $ value );
2020 }
2121 assertType ('mixed ' , $ value );
2222
2323 if (mb_rtrim ($ value ) === '' ) {
2424 assertType ('mixed ' , $ value );
2525 } else {
26- assertType ('non-empty-string ' , $ value );
26+ assertType ('mixed ' , $ value );
2727 }
2828 assertType ('mixed ' , $ value );
2929}
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ function trimMixed($value): void
2121 if (trim ($ value ) === '' ) {
2222 assertType ('mixed ' , $ value );
2323 } else {
24- assertType ('non-empty-string ' , $ value );
24+ assertType ('mixed ' , $ value );
2525 }
2626 assertType ('mixed ' , $ value );
2727
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