Completed
Push — master ( 0aa69f...1f2f47 )
by Hannes
04:03
created

ExpectationFactory::createExpectation()   B

Complexity

Conditions 7
Paths 12

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 8.2222
c 0
b 0
f 0
cc 7
eloc 14
nc 12
nop 2
1
<?php
2
3
namespace hanneskod\readmetester\Expectation;
4
5
/**
6
 * Create expectations from annotation data
7
 */
8
class ExpectationFactory
9
{
10
    /**
11
     * Create expectations from annotation data
12
     *
13
     * @param  string $name Name of expectation
14
     * @param  array  $args Expectation data
15
     * @return ExpectationInterface|null Null if no expectation could be created
16
     */
17
    public function createExpectation($name, array $args)
18
    {
19
        if (empty($args)) {
20
            $args[] = '';
21
        }
22
23
        switch (strtolower($name)) {
24
            case 'expectexception':
25
                return new ExceptionExpectation($args[0]);
26
            case 'expectoutput':
27
                return new OutputExpectation(new Regexp($args[0]));
28
            case 'expectreturntype':
29
                return new ReturnTypeExpectation($args[0]);
30
            case 'expectreturn':
31
                return new ReturnExpectation(new Regexp($args[0]));
32
            case 'expectnothing':
33
                return new NullExpectation;
34
        }
35
    }
36
}
37