OutputGenerator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A writeResolverException() 0 12 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_walk($messages, array($this->output, 'writeln'));
38
    }
39
    
40
    public function writeLines(array $lines)
41
    {
42
        if (!$this->output) {
43
            return;
44
        }
45
        
46
        array_walk($lines, array($this->output, 'writeln'));
47
    }
48
}
49