| Conditions | 5 |
| Paths | 6 |
| Total Lines | 20 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 26 | public static function invertTree2(?TreeNode $root): ?TreeNode |
||
| 27 | { |
||
| 28 | if (!$root) { |
||
| 29 | return null; |
||
| 30 | } |
||
| 31 | $stack = [$root]; |
||
| 32 | while ($stack) { |
||
|
|
|||
| 33 | $node = array_pop($stack); |
||
| 34 | $left = $node->left; |
||
| 35 | $node->left = $node->right; |
||
| 36 | $node->right = $left; |
||
| 37 | if ($node->left) { |
||
| 38 | array_push($stack, $node->left); |
||
| 39 | } |
||
| 40 | if ($node->right) { |
||
| 41 | array_push($stack, $node->right); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | return $root; |
||
| 46 | } |
||
| 48 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.