Passed
Branch master (655a42)
by Allan
03:27 queued 01:16
created

OutputGenerator::writeResolverException()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 14
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
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