ResponseFactory::createInstance()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Meare\Juggler\Imposter\Stub\Response;
4
5
6
use Meare\Juggler\Imposter\Stub\Injection;
7
8
class ResponseFactory
9
{
10
    /**
11
     * @var array
12
     */
13
    private $allowedTypes = [
14
        IResponse::TYPE_IS     => IsResponse::class,
15
        IResponse::TYPE_PROXY  => ProxyResponse::class,
16
        IResponse::TYPE_INJECT => Injection::class,
17
    ];
18
19
    /**
20
     * @param string       $type
21
     * @param array|string $contract
22
     * @return IResponse
23
     */
24 4
    public function createInstance($type, $contract)
25
    {
26 4
        if (!isset($this->allowedTypes[$type])) {
27 1
            throw new \InvalidArgumentException("Cannot create response object; Invalid response type: '$type'");
28
        }
29
30
        /** @var IResponse $class */
31 3
        $class = $this->allowedTypes[$type];
32 3
        return $class::createFromContract($contract);
33
    }
34
}