ResultPrinterFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 16
dl 0
loc 31
c 0
b 0
f 0
ccs 0
cts 14
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A createFromFormat() 0 11 4
1
<?php declare(strict_types=1);
2
3
/**
4
 * @license  http://opensource.org/licenses/mit-license.php MIT
5
 * @link     https://github.com/nicoSWD
6
 * @author   Nicolas Oelgart <[email protected]>
7
 */
8
namespace nicoSWD\SecHeaderCheck\Domain\ResultPrinter;
9
10
final class ResultPrinterFactory
11
{
12
    /** @var ResultPrinterInterface */
13
    private $jsonPrinter;
14
    /** @var ResultPrinterInterface */
15
    private $xmlPrinter;
16
    /** @var ResultPrinterInterface */
17
    private $consolePrinter;
18
19
    public function __construct(
20
        ResultPrinterInterface $jsonPrinter,
21
        ResultPrinterInterface $xmlPrinter,
22
        ResultPrinterInterface $consolePrinter
23
    ) {
24
        $this->jsonPrinter = $jsonPrinter;
25
        $this->xmlPrinter = $xmlPrinter;
26
        $this->consolePrinter = $consolePrinter;
27
    }
28
29
    /** @throws Exception\InvalidOutputFormatException */
30
    public function createFromFormat(string $format, OutputOptions $outputOptions): ResultPrinter
31
    {
32
        switch ($format) {
33
            case OutputFormat::CONSOLE:
34
                return new ResultPrinter($this->consolePrinter, $outputOptions);
35
            case OutputFormat::JSON:
36
                return new ResultPrinter($this->jsonPrinter, $outputOptions);
37
            case OutputFormat::XML:
38
                return new ResultPrinter($this->xmlPrinter, $outputOptions);
39
            default:
40
                throw new Exception\InvalidOutputFormatException();
41
        }
42
    }
43
}
44