IsConstantValueEqualsConstraint   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 34.69 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 3
Metric Value
wmc 6
c 3
b 1
f 3
lcom 1
cbo 1
dl 17
loc 49
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A matches() 17 17 4
A toString() 0 3 1
A __construct() 0 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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