Completed
Push — master ( 7195f8...c1e355 )
by Bill
10s
created

ResultsRendererFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A renderResults() 0 14 3
1
<?php declare(strict_types = 1);
2
3
namespace Churn\Factories;
4
5
use Churn\Renderers\Results\ConsoleResultsRenderer;
6
use Churn\Renderers\Results\JsonResultsRenderer;
7
use Churn\Results\ResultCollection;
8
use InvalidArgumentException;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class ResultsRendererFactory
12
{
13
    const FORMAT_JSON = 'json';
14
    const FORMAT_TEXT = 'text';
15
16
    /**
17
     * Render the results
18
     * @param string           $format  Format to render.
19
     * @param OutputInterface  $output  Output Interface.
20
     * @param ResultCollection $results Result Collection.
21
     * @throws InvalidArgumentException If output format invalid.
22
     * @return void
23
     */
24
    public function renderResults(string $format, OutputInterface $output, ResultCollection $results)
25
    {
26
        if ($format === self::FORMAT_JSON) {
27
            (new JsonResultsRenderer())->render($output, $results);
28
            return;
29
        }
30
31
        if ($format === self::FORMAT_TEXT) {
32
            (new ConsoleResultsRenderer())->render($output, $results);
33
            return;
34
        }
35
36
        throw new InvalidArgumentException('Invalid output format provided');
37
    }
38
}
39