IsConstantDefinedConstraint   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 42.31 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 0
cbo 1
dl 11
loc 26
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A matches() 11 11 4
A toString() 0 3 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.
5
 *
6
 * BuildR PHP Framework
7
 *
8
 * @author Zoltán Borsos <[email protected]>
9
 * @package TestTools
10
 * @subpackage Asserts
11
 *
12
 * @copyright    Copyright 2016, Zoltán Borsos.
13
 * @license      https://github.com/BuildrPHP/Test-Tools/blob/master/LICENSE.md
14
 * @link         https://github.com/BuildrPHP/Test-Tools
15
 */
16
class IsConstantDefinedConstraint extends \PHPUnit_Framework_Constraint {
17
18
    /**
19
     * {@inheritDoc}
20
     */
21 3 View Code Duplication
    protected function matches($other) {
22 3
        if(!is_string($other)) {
23 1
            return FALSE;
24
        }
25
26 2
        if(is_string($other) && defined($other)) {
27 1
            return TRUE;
28
        }
29
30 1
        return FALSE;
31
    }
32
33
34
    /**
35
     * {@inheritDoc}
36
     */
37 2
    public function toString() {
38 2
        return 'constant is defined';
39
    }
40
41
}
42