Completed
Push — master ( f7d051...7cf7a4 )
by Sébastien
03:48
created

ReportRunnerFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 16
c 0
b 0
f 0
ccs 9
cts 9
cp 1
rs 9.4285
cc 2
eloc 9
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\Jasper;
6
7
use Soluble\Jasper\ReportRunner\ReportRunnerInterface;
8
use Soluble\Jasper\ReportRunner\JaphaJasperV6Runner;
9
use Soluble\Japha\Bridge\Adapter as BridgeAdapter;
10
11
class ReportRunnerFactory
12
{
13
    public const JAPHA_JASPER_V6 = 'japha_jasper_v6';
14
15
    public const SUPPORTED_RUNNERS = [
16
        self::JAPHA_JASPER_V6 => JaphaJasperV6Runner::class
17
    ];
18
19 2
    public function __invoke(BridgeAdapter $bridgeAdapter, string $runner = self::JAPHA_JASPER_V6): ReportRunnerInterface
20
    {
21 2
        if (!array_key_exists($runner, self::SUPPORTED_RUNNERS)) {
22 1
            throw new Exception\UnsupportedRunnerException(
23 1
                sprintf(
24 1
                    'Unsupported runner "%s", must be in (%s)',
25 1
                    $runner,
26 1
                    implode(',', array_keys(self::SUPPORTED_RUNNERS))
27
                )
28
            );
29
        }
30
31 1
        $class = self::SUPPORTED_RUNNERS[$runner];
32
33 1
        return new $class($bridgeAdapter);
34
    }
35
}
36