Matcher::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PHPKitchen\CodeSpecsCore\Expectation\Matcher\Base;
4
5
use PHPKitchen\CodeSpecsCore\Contract\ExpectationMatcher;
6
use PHPKitchen\CodeSpecsCore\Expectation\Internal\Assert;
7
8
/**
9
 * Matcher is a base class for all of the expectation matchers.
10
 *
11
 * @package PHPKitchen\CodeSpecsCore\Base
12
 * @author Dmitry 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
        return $this->assert;
28
    }
29
30
    public function __invoke($actualValue) {
31
        $newMatcher = clone $this;
32
33
        $newMatcher->assert->switchToInTimeExecutionStrategy();
34
        $newMatcher->assert->runStepsWithActualValue($actualValue);
35
        return $newMatcher;
36
    }
37
38
    protected function createInternalMatcherWithDescription($matcherClass, $description) {
39
        $assert = clone $this->assert;
40
        $assert->changeDescriptionTo($description);
41
        return new $matcherClass($assert);
42
    }
43
44
    protected function getActualValue() {
45
        return $this->assert->getActualValue();
46
    }
47
}