Passed
Push — master ( cc8c81...f0282f )
by Christopher
04:33
created

TOperandTypeTest   D

Complexity

Total Complexity 61

Size/Duplication

Total Lines 567
Duplicated Lines 59.26 %

Coupling/Cohesion

Components 2
Dependencies 16

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 61
lcom 2
cbo 16
dl 336
loc 567
rs 4.054
c 3
b 0
f 0

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like TOperandTypeTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use TOperandTypeTest, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace AlgoWeb\ODataMetadata\Tests\v3\edm;
4
5
use AlgoWeb\ODataMetadata\MetadataV3\edm\TOperandType;
6
use AlgoWeb\ODataMetadata\Tests\TestCase;
7
8
class TOperandTypeTest extends TestCase
9
{
10
    public function testSetStringNullString()
11
    {
12
        $foo = new TOperandType();
13
        $foo->setString(null);
14
        $this->assertEquals(null, $foo->getString());
15
    }
16
17
    public function testSetStringActualString()
18
    {
19
        $foo = new TOperandType();
20
        $foo->setString("string");
21
        $this->assertEquals('string', $foo->getString());
22
    }
23
24
    public function testSetStringEmptyArrayAsString()
25
    {
26
        $expected = "String must be a string";
27
        $actual = null;
28
29
        $foo = new TOperandType();
30
        try {
31
            $foo->setString([]);
32
        } catch (\InvalidArgumentException $e) {
33
            $actual = $e->getMessage();
34
        }
35
        $this->assertEquals($expected, $actual);
36
    }
37
38
    public function testSetStringNonEmptyArrayAsString()
39
    {
40
        $expected = "String must be a string";
41
        $actual = null;
42
43
        $foo = new TOperandType();
44
        try {
45
            $foo->setString(['a']);
46
        } catch (\InvalidArgumentException $e) {
47
            $actual = $e->getMessage();
48
        }
49
        $this->assertEquals($expected, $actual);
50
    }
51
52
    public function testSetStringObjectAsString()
53
    {
54
        $expected = "String must be a string";
55
        $actual = null;
56
57
        $foo = new TOperandType();
58
        try {
59
            $foo->setString(new \DateTime());
60
        } catch (\InvalidArgumentException $e) {
61
            $actual = $e->getMessage();
62
        }
63
        $this->assertEquals($expected, $actual);
64
    }
65
}
66