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: