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

GreaterThanOrEqualMatcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
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
 * GreaterThanOrEqualMatcher matches that the actual value is greater than or equal
9
 * to the expected value.
10
 *
11
 * @package Peridot\Leo\Matcher
12
 */
13
class GreaterThanOrEqualMatcher extends CountableMatcher
14
{
15
    /**
16
     * Match that the actual number is greater than or equal
17
     * to the expected value.
18
     *
19
     * @param $number
20
     * @return bool
21
     */
22
    protected function matchNumeric($number)
23
    {
24
        return $number >= $this->expected;
25
    }
26
27
    /**
28
     * Return a default template if none was set.
29
     *
30
     * @return TemplateInterface
31
     */
32
    public function getDefaultTemplate()
33
    {
34
        return new ArrayTemplate([
35
            'default' => 'Expected {{actual}} to be at least {{expected}}',
36
            'negated' => 'Expected {{actual}} to be below {{expected}}'
37
        ]);
38
    }
39
40
    /**
41
     * Return a default template for when a countable has been set.
42
     *
43
     * @return TemplateInterface
44
     */
45
    public function getDefaultCountableTemplate()
46
    {
47
        $count = $this->getCount();
48
        return new ArrayTemplate([
49
            'default' => "Expected {{actual}} to have a length at least {{expected}} but got $count",
50
            'negated' => 'Expected {{actual}} to have a length below {{expected}}'
51
        ]);
52
    }
53
}
54