Completed
Pull Request — master (#23)
by Erin
03:28
created

TypeMatcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 5 1
A doMatch() 0 5 1
A getDefaultTemplate() 0 7 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
 * 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