OutputAnalyser   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B scanOutputForFailures() 0 35 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($failureMessages, function ($pattern) use ($output) {
13
            return $pattern && preg_match($pattern, $output);
14
        });
15
16
        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...
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