Completed
Branch develop (b42baf)
by Adrien
11:23
created

ComplexAssert   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 57
Duplicated Lines 31.58 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 18
loc 57
rs 10
wmc 12
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
C assertComplexEquals() 18 47 11
A getErrorMessage() 0 4 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
2
3
namespace PhpSpreadsheetTests\Custom;
4
5
class ComplexAssert
6
{
7
    private $_errorMessage = '';
8
9
    public function assertComplexEquals($expected, $actual, $delta = 0)
10
    {
11
        if ($expected{0} === '#') {
12
            //    Expecting an error, so we do a straight string comparison
13
            if ($expected === $actual) {
14
                return true;
15
            }
16
            $this->_errorMessage = 'Expected Error: ' . $actual . ' !== ' . $expected;
17
18
            return false;
19
        }
20
21
        $expectedComplex = new Complex($expected);
22
        $actualComplex = new Complex($actual);
23
24
        if (!is_numeric($actualComplex->getReal()) || !is_numeric($expectedComplex->getReal())) {
25 View Code Duplication
            if ($actualComplex->getReal() !== $expectedComplex->getReal()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
                $this->_errorMessage = 'Mismatched String: ' . $actualComplex->getReal() . ' !== ' . $expectedComplex->getReal();
27
28
                return false;
29
            }
30
31
            return true;
32
        }
33
34 View Code Duplication
        if ($actualComplex->getReal() < ($expectedComplex->getReal() - $delta) ||
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
            $actualComplex->getReal() > ($expectedComplex->getReal() + $delta)) {
36
            $this->_errorMessage = 'Mismatched Real part: ' . $actualComplex->getReal() . ' != ' . $expectedComplex->getReal();
37
38
            return false;
39
        }
40
41 View Code Duplication
        if ($actualComplex->getImaginary() < ($expectedComplex->getImaginary() - $delta) ||
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
            $actualComplex->getImaginary() > ($expectedComplex->getImaginary() + $delta)) {
43
            $this->_errorMessage = 'Mismatched Imaginary part: ' . $actualComplex->getImaginary() . ' != ' . $expectedComplex->getImaginary();
44
45
            return false;
46
        }
47
48 View Code Duplication
        if ($actualComplex->getSuffix() !== $actualComplex->getSuffix()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
            $this->_errorMessage = 'Mismatched Suffix: ' . $actualComplex->getSuffix() . ' != ' . $expectedComplex->getSuffix();
50
51
            return false;
52
        }
53
54
        return true;
55
    }
56
57
    public function getErrorMessage()
58
    {
59
        return $this->_errorMessage;
60
    }
61
}
62