Test Failed
Push — master ( 57b7d4...e042c7 )
by Hannes
02:15
created

ExpectationFactory::createExpectation()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 5
nc 3
nop 1
dl 0
loc 11
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace hanneskod\readmetester\Expectation;
6
7
use hanneskod\readmetester\Annotations;
8
use hanneskod\readmetester\Parser\Annotation;
9
10
/**
11
 * Create expectations from annotation data
12
 */
13
class ExpectationFactory
14
{
15
    public function createExpectation(Annotation $annotation): ?ExpectationInterface
16
    {
17
        if ($annotation->isNamed(Annotations::ANNOTATION_EXPECT_OUTPUT)) {
18
            return new OutputExpectation(new Regexp($annotation->getArgument() ?: '//'));
19
        }
20
21
        if ($annotation->isNamed(Annotations::ANNOTATION_EXPECT_ERROR)) {
22
            return new ErrorExpectation(new Regexp($annotation->getArgument() ?: '//'));
23
        }
24
25
        return null;
26
    }
27
}
28