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: * TypeMatcher determines if an actual value has the same type as the expected type.
9: *
10: * @package Peridot\Leo\Matcher
11: */
12: class TypeMatcher extends AbstractMatcher
13: {
14: /**
15: * @var string
16: */
17: protected $type;
18:
19: /**
20: * {@inheritdoc}
21: *
22: * @param $actual
23: * @return Match
24: */
25: public function match($actual)
26: {
27: $match = parent::match($actual);
28: return $match->setActual($this->type);
29: }
30:
31: /**
32: * Determine if the actual value has the same type as the expected value. Uses the native gettype()
33: * function to compare.
34: *
35: * @param $actual
36: * @return bool
37: */
38: public function doMatch($actual)
39: {
40: $this->type = gettype($actual);
41: return $this->expected === $this->type;
42: }
43:
44: /**
45: * {@inheritdoc}
46: *
47: * @return TemplateInterface
48: */
49: public function getDefaultTemplate()
50: {
51: return new ArrayTemplate([
52: 'default' => 'Expected {{expected}}, got {{actual}}',
53: 'negated' => 'Expected a type other than {{expected}}'
54: ]);
55: }
56: }
57: