1 | <?php |
||
2 | /** |
||
3 | * Copyright © Vaimo Group. All rights reserved. |
||
4 | * See LICENSE_VAIMO.txt for license details. |
||
5 | */ |
||
6 | namespace Vaimo\ComposerPatches\Console; |
||
7 | |||
8 | class OutputAnalyser |
||
9 | { |
||
10 | public function scanOutputForFailures($output, $separatorMatcher, array $failureMessages) |
||
11 | { |
||
12 | $patternsWithResults = array_filter($failureMessages, function ($pattern) use ($output) { |
||
13 | return $pattern && preg_match($pattern, $output); |
||
14 | }); |
||
15 | |||
16 | if (!$patternsWithResults) { |
||
0 ignored issues
–
show
|
|||
17 | return array(); |
||
18 | } |
||
19 | |||
20 | $lines = explode(PHP_EOL, $output); |
||
21 | |||
22 | $matches = array(); |
||
23 | |||
24 | foreach ($patternsWithResults as $patternCode => $pattern) { |
||
25 | if (!isset($matches[$pattern])) { |
||
26 | $matches[$patternCode] = array(); |
||
27 | } |
||
28 | |||
29 | foreach ($lines as $line) { |
||
30 | if (preg_match($separatorMatcher, $line)) { |
||
31 | $matches[$patternCode][] = $line; |
||
32 | |||
33 | continue; |
||
34 | } |
||
35 | |||
36 | if (!preg_match($pattern, $line)) { |
||
37 | continue; |
||
38 | } |
||
39 | |||
40 | $matches[$patternCode][] = $line; |
||
41 | } |
||
42 | } |
||
43 | |||
44 | return $matches; |
||
45 | } |
||
46 | } |
||
47 |
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.