PredicateFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createInstance() 0 8 2
A createInjection() 0 8 2
A createPredicate() 0 8 2
1
<?php
2
3
namespace Meare\Juggler\Imposter\Stub\Predicate;
4
5
6
use Meare\Juggler\Imposter\Stub\Injection;
7
8
class PredicateFactory
9
{
10
    /**
11
     * @param string       $type
12
     * @param string|array $contract
13
     * @return IPredicate
14
     */
15 4
    public function createInstance($type, $contract)
16
    {
17 4
        if (IPredicate::OPERATOR_INJECT === $type) {
18 2
            return $this->createInjection($contract);
19
        } else {
20 2
            return $this->createPredicate($type, $contract);
21
        }
22
    }
23
24
    /**
25
     * @param mixed $contract
26
     * @return Injection
27
     */
28 2
    private function createInjection($contract)
29
    {
30 2
        if (!is_string($contract)) {
31 1
            throw new \InvalidArgumentException('Cannot create predicate object; $contract must be string for "inject" predicate');
32
        }
33
34 1
        return Injection::createFromContract($contract);
35
    }
36
37
    /**
38
     * @param string $type
39
     * @param mixed  $contract
40
     * @return Predicate
41
     */
42 2
    private function createPredicate($type, $contract)
43
    {
44 2
        if (!is_array($contract)) {
45 1
            throw new \InvalidArgumentException("Cannot create predicate object; $contract must be array for '$type' predicate");
46
        }
47
48 1
        return Predicate::createFromContract([$type => $contract]);
49
    }
50
}