ResponseFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A createInstance() 0 10 2
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
}