Passed
Push — master ( 42c4d1...80535d )
by Allan
02:39 queued 12s
created

OutputAnalyser   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 20
dl 0
loc 40
rs 10
c 1
b 0
f 1
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B scanOutputForFailures() 0 38 8
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(
13
            $failureMessages,
14
            function ($pattern) use ($output) {
15
                return $pattern && preg_match($pattern, $output);
16
            }
17
        );
18
19
        if (!$patternsWithResults) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $patternsWithResults of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

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.

Loading history...
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
    }
49
}
50