ImposterBuilder::build()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
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
}