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

ComplexAssert::getErrorMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
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