Completed
Pull Request — master (#543)
by
unknown
02:43
created

ConstraintMatcher   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 40
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A match() 0 12 3
A __toString() 0 4 1
1
<?php
2
namespace Mockery\Matcher;
3
4
class ConstraintMatcher extends MatcherAbstract
5
{
6
    protected $constraint;
7
    protected $rethrow;
8
9
    /**
10
     * @param \PHPUnit_Framework_Constraint $constraint
11
     * @param bool $rethrow
12
     */
13 3
    public function __construct(\PHPUnit_Framework_Constraint $constraint, $rethrow = false)
14
    {
15 3
        $this->constraint = $constraint;
16 3
        $this->rethrow = $rethrow;
17 3
    }
18
19
    /**
20
     * @param mixed $actual
21
     * @return bool
22
     */
23 2
    public function match(&$actual)
24
    {
25
        try {
26 2
            $this->constraint->evaluate($actual);
27 1
            return true;
28 2
        } catch (\PHPUnit_Framework_AssertionFailedError $e) {
29 2
            if ($this->rethrow) {
30 1
                throw $e;
31
            }
32 1
            return false;
33
        }
34
    }
35
36
    /**
37
     *
38
     */
39 1
    public function __toString()
40
    {
41 1
        return '<Constraint>';
42
    }
43
}
44