Matcher   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 7 1
A startStep() 0 4 1
A __construct() 0 2 1
A getActualValue() 0 2 1
A createInternalMatcherWithDescription() 0 5 1
A __clone() 0 2 1
1
<?php
2
3
namespace PHPKitchen\CodeSpecs\Expectation\Matcher\Base;
4
5
use PHPKitchen\CodeSpecs\Contract\ExpectationMatcher;
6
use PHPKitchen\CodeSpecs\Expectation\Internal\Assert;
7
8
/**
9
 * Matcher is a base class for all of the expectation matchers.
10
 *
11
 * @package PHPKitchen\CodeSpecs\Base
12
 * @author Dima Kolodko <[email protected]>
13
 */
14
abstract class Matcher implements ExpectationMatcher {
15
    private $assert;
16
17
    public function __construct(Assert $assert) {
18
        $this->assert = $assert;
19
    }
20
21
    public function __clone() {
22
        $this->assert = clone $this->assert;
23
    }
24
25
    protected function startStep($stepName) {
26
        $this->assert->changeCurrentStepTo($stepName);
27
28
        return $this->assert;
29
    }
30
31
    public function __invoke($actualValue) {
32
        $newMatcher = clone $this;
33
34
        $newMatcher->assert->switchToInTimeExecutionStrategy();
35
        $newMatcher->assert->runStepsWithActualValue($actualValue);
36
37
        return $newMatcher;
38
    }
39
40
    protected function createInternalMatcherWithDescription($matcherClass, $description) {
41
        $assert = clone $this->assert;
42
        $assert->changeDescriptionTo($description);
43
44
        return new $matcherClass($assert);
45
    }
46
47
    protected function getActualValue() {
48
        return $this->assert->getActualValue();
49
    }
50
}