PredicateMatcher::doMatch()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Peridot\Leo\Matcher;
4
5
use Peridot\Leo\Matcher\Template\ArrayTemplate;
6
use Peridot\Leo\Matcher\Template\TemplateInterface;
7
8
/**
9
 * PredicateMatcher executes a function with the actual value. The PredicateMatcher returns
10
 * the result of that function call as a Match result.
11
 *
12
 * @package Peridot\Leo\Matcher
13
 */
14
class PredicateMatcher extends AbstractMatcher
15
{
16
    /**
17
     * {@inheritdoc}
18
     *
19
     * @return TemplateInterface
20
     */
21
    public function getDefaultTemplate()
22
    {
23
        return new ArrayTemplate([
24
            'default' => 'Expected {{actual}} to satisfy {{expected}}',
25
            'negated' => 'Expected {{actual}} to not satisfy {{expected}}',
26
        ]);
27
    }
28
29
    /**
30
     * Match actual value against the expected predicate.
31
     *
32
     * @param $actual
33
     * @return mixed
34
     */
35
    protected function doMatch($actual)
36
    {
37
        return (bool) call_user_func_array($this->expected, [$actual]);
38
    }
39
}
40