ResultsRendererFactory::getRenderer()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 19
rs 9.6111
cc 5
nc 5
nop 1
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