ImposterBuilder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 4
cts 6
cp 0.6667
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
build() 0 1 ?
A validateContractProtocol() 0 9 3
1
<?php
2
3
namespace Meare\Juggler\Imposter\Builder;
4
5
6
use Meare\Juggler\Imposter\Imposter;
7
8
abstract class ImposterBuilder
9
{
10
    /**
11
     * @var string Expected contract protocol
12
     */
13
    protected $protocol;
14
15
    /**
16
     * Builds Imposter object from decoded contract
17
     *
18
     * @param array $contract
19
     * @return Imposter
20
     */
21
    abstract public function build(array $contract);
22
23
    /**
24
     * @param array $contract
25
     * @throws \InvalidArgumentException if contract protocol is not set or does not match expected
26
     */
27 3
    protected function validateContractProtocol(array $contract)
28
    {
29 3
        if (!isset($contract['protocol'])) {
30
            throw new \InvalidArgumentException('Unable to build Imposter; Invalid contract given; missing \'protocol\'');
31
        }
32 3
        if ($contract['protocol'] !== $this->protocol) {
33
            throw new \InvalidArgumentException("Unable to build Imposter; expected contract protocol to be '{$this->protocol}'; got '{$contract['protocol']}'");
34
        }
35
    }
36
}