ExpectationEvaluator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 12
c 0
b 0
f 0
dl 0
loc 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A evaluate() 0 19 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace hanneskod\readmetester\Expectation;
6
7
use hanneskod\readmetester\Runner\OutcomeInterface;
8
9
class ExpectationEvaluator
10
{
11
    /**
12
     * Evaluate expectations against an outcome
13
     *
14
     * If outcome is marked as mustBeHandled it must be handled by at least one
15
     * expectation. Expectations that does not handle an outcome triggers failure.
16
     *
17
     * @return array<StatusInterface>
18
     */
19
    public function evaluate(OutcomeInterface $outcome): array
20
    {
21
        $statuses = [];
22
        $isHandled = !$outcome->mustBeHandled();
23
24
        foreach ($outcome->getExample()->getExpectations() as $index => $expectation) {
25
            if ($expectation->handles($outcome)) {
26
                $statuses[$index] = $expectation->handle($outcome);
27
                $isHandled = true;
28
            } else {
29
                $statuses[$index] = new Failure($outcome, "Failed {$expectation->getDescription()}");
30
            }
31
        }
32
33
        if (!$isHandled) {
34
            $statuses[] = new Failure($outcome, 'Unhandled ' . $outcome->getDescription());
35
        }
36
37
        return $statuses;
38
    }
39
}
40