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

ComplexAssert::assertComplexEquals()   C

Complexity

Conditions 11
Paths 8

Size

Total Lines 47
Code Lines 25

Duplication

Lines 18
Ratio 38.3 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
eloc 25
c 1
b 0
f 0
nc 8
nop 3
dl 18
loc 47
rs 5.2653

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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