| Conditions | 8 |
| Paths | 10 |
| Total Lines | 38 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 10 | public function scanOutputForFailures($output, $separatorMatcher, array $failureMessages) |
||
| 11 | { |
||
| 12 | $patternsWithResults = array_filter( |
||
| 13 | $failureMessages, |
||
| 14 | function ($pattern) use ($output) { |
||
| 15 | return $pattern && preg_match($pattern, $output); |
||
| 16 | } |
||
| 17 | ); |
||
| 18 | |||
| 19 | if (!$patternsWithResults) { |
||
|
|
|||
| 20 | return array(); |
||
| 21 | } |
||
| 22 | |||
| 23 | $lines = explode(PHP_EOL, $output); |
||
| 24 | |||
| 25 | $matches = array(); |
||
| 26 | |||
| 27 | foreach ($patternsWithResults as $patternCode => $pattern) { |
||
| 28 | if (!isset($matches[$pattern])) { |
||
| 29 | $matches[$patternCode] = array(); |
||
| 30 | } |
||
| 31 | |||
| 32 | foreach ($lines as $line) { |
||
| 33 | if (preg_match($separatorMatcher, $line)) { |
||
| 34 | $matches[$patternCode][] = $line; |
||
| 35 | |||
| 36 | continue; |
||
| 37 | } |
||
| 38 | |||
| 39 | if (!preg_match($pattern, $line)) { |
||
| 40 | continue; |
||
| 41 | } |
||
| 42 | |||
| 43 | $matches[$patternCode][] = $line; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | return $matches; |
||
| 48 | } |
||
| 50 |
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.