File tree Expand file tree Collapse file tree
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3749,11 +3749,16 @@ private function createConditionalExpressions(
37493749
37503750 foreach ($ variableTypeGuards as $ guardExprString => $ guardHolder ) {
37513751 if (
3752- array_key_exists ($ exprString , $ theirExpressionTypes )
3753- && $ theirExpressionTypes [$ exprString ]->getCertainty ()->yes ()
3754- && array_key_exists ($ guardExprString , $ theirExpressionTypes )
3752+ array_key_exists ($ guardExprString , $ theirExpressionTypes )
37553753 && $ theirExpressionTypes [$ guardExprString ]->getCertainty ()->yes ()
3756- && !$ guardHolder ->getType ()->isSuperTypeOf ($ theirExpressionTypes [$ guardExprString ]->getType ())->no ()
3754+ && (
3755+ (
3756+ array_key_exists ($ exprString , $ theirExpressionTypes )
3757+ && $ theirExpressionTypes [$ exprString ]->getCertainty ()->yes ()
3758+ && !$ guardHolder ->getType ()->isSuperTypeOf ($ theirExpressionTypes [$ guardExprString ]->getType ())->no ()
3759+ )
3760+ || $ guardHolder ->getType ()->isSuperTypeOf ($ theirExpressionTypes [$ guardExprString ]->getType ())->yes ()
3761+ )
37573762 ) {
37583763 continue ;
37593764 }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Bug14595 ;
4+
5+ use function PHPStan \Testing \assertType ;
6+
7+ /**
8+ * @param array{
9+ * multiple: 0|1|2
10+ * , total: bool
11+ * } $options
12+ */
13+ function arrayAppendGuard (array $ options ): void {
14+ $ instructions = [ ];
15+ $ instructions [] = "foo " ;
16+ if ($ options ['multiple ' ] != 1 || $ options ['total ' ])
17+ $ instructions [] = "bar " ;
18+ assertType ('0|1|2 ' , $ options ['multiple ' ]);
19+ if (!$ options ['total ' ])
20+ $ instructions [] = "baz " ;
21+ assertType ('0|1|2 ' , $ options ['multiple ' ]);
22+ if (!$ options ['total ' ])
23+ $ instructions [] = "qux " ;
24+ assertType ('0|1|2 ' , $ options ['multiple ' ]);
25+ }
26+
27+ /**
28+ * @param array{
29+ * multiple: 0|1|2
30+ * , total: bool
31+ * } $options
32+ */
33+ function strictComparisonGuard (array $ options ): void {
34+ $ instructions = [ ];
35+ $ instructions [] = "foo " ;
36+ if ($ options ['multiple ' ] !== 1 || $ options ['total ' ])
37+ $ instructions [] = "bar " ;
38+ assertType ('0|1|2 ' , $ options ['multiple ' ]);
39+ if (!$ options ['total ' ])
40+ $ instructions [] = "baz " ;
41+ assertType ('0|1|2 ' , $ options ['multiple ' ]);
42+ if (!$ options ['total ' ])
43+ $ instructions [] = "qux " ;
44+ assertType ('0|1|2 ' , $ options ['multiple ' ]);
45+ }
You can’t perform that action at this time.
0 commit comments