IsConstantValueEqualsConstraint::matches()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 8

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 17
loc 17
ccs 7
cts 7
cp 1
rs 9.2
cc 4
eloc 8
nc 4
nop 1
crap 4
1
<?php namespace BuildR\TestTools\Asserts;
2
3
/**
4
 * Custom PHPUnit Constraint that check whenever a constant is defined and the value
5
 * is matches with the given value
6
 *
7
 * BuildR PHP Framework
8
 *
9
 * @author Zoltán Borsos <[email protected]>
10
 * @package TestTools
11
 * @subpackage Asserts
12
 *
13
 * @copyright    Copyright 2016, Zoltán Borsos.
14
 * @license      https://github.com/BuildrPHP/Test-Tools/blob/master/LICENSE.md
15
 * @link         https://github.com/BuildrPHP/Test-Tools
16
 */
17
class IsConstantValueEqualsConstraint extends \PHPUnit_Framework_Constraint {
18
19
20
21
    /**
22
     * @type mixed
23
     */
24
    protected $value;
25
26
    /**
27
     * IsConstantValueEqualsConstraint constructor
28
     *
29
     * @param $value mixed
30
     */
31 6
    public function __construct($value) {
32 6
        parent::__construct();
33
34 6
        $this->value = $value;
35 6
    }
36
37
    /**
38
     * {@inheritDoc}
39
     */
40 6 View Code Duplication
    protected function matches($other) {
41 6
        if(!is_string($other)) {
42 1
            return FALSE;
43
        }
44
45 5
        if(!defined($other)) {
46 1
            return FALSE;
47
        }
48
49 4
        if(constant($other) === $this->value) {
50 4
            return TRUE;
51
        }
52
53
        //@codeCoverageIgnoreStart
54
        return FALSE;
55
        //@codeCoverageIgnoreEnd
56
    }
57
58
    /**
59
     * {@inheritDoc}
60
     */
61 2
    public function toString() {
62 2
        return 'constant value is equals to \'' . $this->value . '\'';
63
    }
64
65
}
66