Passed
Push — master ( dd20c7...9b85cd )
by Allan
02:33
created

OutputGenerator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateForException() 0 24 4
A __construct() 0 4 1
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 OutputGenerator
9
{
10
    /**
11
     * @var \Vaimo\ComposerPatches\Logger 
12
     */
13
    private $logger;
14
    
15
    public function __construct(
16
        \Vaimo\ComposerPatches\Logger $logger
17
    ) {
18
        $this->logger = $logger;
19
    }
20
21
    public function generateForException(\Exception $exception)
22
    {
23
        if ($exception instanceof \Vaimo\ComposerPatches\Exceptions\ApplierFailure) {
24
            $messages = array_filter($exception->getErrors());
25
26
            if (!$messages) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $messages 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...
27
                return;
28
            }
29
30
            $lines = array(
31
                'Most likely causes for the failure:',
32
                ''
33
            );
34
35
            foreach ($messages as $type => $errors) {
36
                $lines[] = sprintf('* %s: %s', $type, reset($errors));
37
            }
38
39
            $lines = array_merge($lines, array(
40
                '',
41
                '(For full, unfiltered details please use: composer patch:apply -vvv)'
42
            ));
43
44
            $this->logger->writeNotice('warning', $lines);
45
        }
46
    }
47
}
48