Completed
Pull Request — master (#22)
by Erin
02:35
created

PredicateMatcher   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 26
rs 10

2 Methods

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