| Conditions | 7 |
| Paths | 8 |
| Total Lines | 14 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | public function __construct(array $matrix) |
||
| 13 | { |
||
| 14 | $this->matrix = $matrix; |
||
| 15 | [$m, $n] = [count($matrix), is_array($matrix[0]) ? count($matrix[0]) : 0]; |
||
| 16 | if (!$matrix || $m <= 0 || $n <= 0) { |
||
|
|
|||
| 17 | return 0; |
||
| 18 | } |
||
| 19 | $this->dp = array_fill(0, $m + 1, array_fill(0, $n + 1, 0)); |
||
| 20 | for ($i = 1; $i <= $m; $i++) { |
||
| 21 | for ($j = 1; $j <= $n; $j++) { |
||
| 22 | $this->dp[$i][$j] = $this->dp[$i - 1][$j] |
||
| 23 | + $this->dp[$i][$j - 1] |
||
| 24 | - $this->dp[$i - 1][$j - 1] |
||
| 25 | + $this->matrix[$i - 1][$j - 1]; |
||
| 26 | } |
||
| 43 |
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.