Passed
Push — master ( aa9b83...655a42 )
by Allan
01:58
created

OutputGenerator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 14
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A writeResolverException() 0 14 2
A writeLines() 0 7 2
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerChangelogs\Console;
7
8
use Vaimo\ComposerChangelogs\Exceptions\PackageResolverException;
9
10
class OutputGenerator
11
{
12
    /**
13
     * @var \Symfony\Component\Console\Output\OutputInterface
14
     */
15
    private $output;
16
17
    /**
18
     * @param \Symfony\Component\Console\Output\OutputInterface $output
19
     */
20
    public function __construct(
21
        \Symfony\Component\Console\Output\OutputInterface $output = null
22
    ) {
23
        $this->output = $output;
24
    }
25
26
    public function writeResolverException(PackageResolverException $exception)
27
    {
28
        if (!$this->output) {
29
            return;
30
        }
31
        
32
        $messages = array_merge(
33
            array(sprintf('<error>%s</error>', $exception->getMessage())),
34
            array_filter((array)$exception->getExtraInfo())
35
        );
36
        
37
        array_map(
38
            array($this->output, 'writeln'),
39
            $messages
40
        );
41
    }
42
    
43
    public function writeLines(array $lines)
44
    {
45
        if (!$this->output) {
46
            return;
47
        }
48
        
49
        array_map(array($this->output, 'writeln'), $lines);
50
    }
51
}
52