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

LessThanOrEqualMatcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A matchNumeric() 0 4 1
A getDefaultTemplate() 0 7 1
A getDefaultCountableTemplate() 0 8 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
 * LessThanOrEqualMatcher determines if an actual value is less than or equal to the expected value.
9
 *
10
 * @package Peridot\Leo\Matcher
11
 */
12
class LessThanOrEqualMatcher extends CountableMatcher
13
{
14
    /**
15
     * Match that the actual number is less than or equal
16
     * to the expected value.
17
     *
18
     * @param $number
19
     * @return bool
20
     */
21
    protected function matchNumeric($number)
22
    {
23
        return $number <= $this->expected;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     *
29
     * @return TemplateInterface
30
     */
31
    public function getDefaultTemplate()
32
    {
33
        return new ArrayTemplate([
34
            'default' => 'Expected {{actual}} to be at most {{expected}}',
35
            'negated' => 'Expected {{actual}} to be above {{expected}}'
36
        ]);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     *
42
     * @return TemplateInterface
43
     */
44
    public function getDefaultCountableTemplate()
45
    {
46
        $count = $this->getCount();
47
        return new ArrayTemplate([
48
            'default' => "Expected {{actual}} to have a length at most {{expected}} but got $count",
49
            'negated' => 'Expected {{actual}} to have a length above {{expected}}'
50
        ]);
51
    }
52
}
53