ResultsRendererFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRenderer() 0 19 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Churn\Result;
6
7
use Churn\Result\Render\ConsoleResultsRenderer;
8
use Churn\Result\Render\CsvResultsRenderer;
9
use Churn\Result\Render\JsonResultsRenderer;
10
use Churn\Result\Render\MarkdownResultsRenderer;
11
use Churn\Result\Render\ResultsRendererInterface;
12
use InvalidArgumentException;
13
14
/**
15
 * @internal
16
 */
17
final class ResultsRendererFactory
18
{
19
    private const FORMAT_CSV = 'csv';
20
    private const FORMAT_JSON = 'json';
21
    private const FORMAT_MD = 'markdown';
22
    private const FORMAT_TEXT = 'text';
23
24
    /**
25
     * Render the results
26
     *
27
     * @param string $format Format to render.
28
     * @throws InvalidArgumentException If output format invalid.
29
     */
30
    public function getRenderer(string $format): ResultsRendererInterface
31
    {
32
        if (self::FORMAT_CSV === $format) {
33
            return new CsvResultsRenderer();
34
        }
35
36
        if (self::FORMAT_JSON === $format) {
37
            return new JsonResultsRenderer();
38
        }
39
40
        if (self::FORMAT_MD === $format) {
41
            return new MarkdownResultsRenderer();
42
        }
43
44
        if (self::FORMAT_TEXT === $format) {
45
            return new ConsoleResultsRenderer();
46
        }
47
48
        throw new InvalidArgumentException('Invalid output format provided');
49
    }
50
}
51