Conditions | 1 |
Paths | 1 |
Total Lines | 54 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
18 | public function testIntersection() |
||
19 | { |
||
20 | $xml = new Person("Alex", "Letni", [ |
||
21 | new Head("small", null, [ |
||
22 | new XmlConvertibleObject('Eye'), |
||
23 | new XmlConvertibleObject('Eye', [ |
||
24 | new Person('Adam', 'Morgan'), |
||
25 | ]), |
||
26 | ]) |
||
27 | ]); |
||
28 | |||
29 | $compared = new Person("Alex", "Letni", [ |
||
30 | new Head('small', null, [ |
||
31 | new XmlConvertibleObject('Eye', [ |
||
32 | new Person('Adam', 'Morgan'), |
||
33 | ]), |
||
34 | ]) |
||
35 | ]); |
||
36 | |||
37 | |||
38 | $result = $xml->xmlIntersect($compared); |
||
39 | $this->assertInstanceOf(Person::class, $result); |
||
40 | /** @var Person $result */ |
||
41 | |||
42 | $this->assertEquals($result->name, $compared->name); |
||
43 | $this->assertEquals($result->name, $xml->name); |
||
44 | $this->assertNotNull($result->xmlChildren); |
||
45 | $this->assertCount(1, $result->xmlChildren); |
||
46 | $this->assertInstanceOf(Head::class, $result->xmlChildren[0]); |
||
47 | $this->assertNotNull($result->xmlChildren[0]->xmlChildren); |
||
48 | $this->assertCount(1, $result->xmlChildren[0]->xmlChildren); |
||
49 | // Eye |
||
50 | $this->assertInstanceOf(XmlConvertibleObject::class, $result->xmlChildren[0]->xmlChildren[0]); |
||
51 | $this->assertNotNull( |
||
52 | $result->xmlChildren[0]->xmlChildren[0]->xmlChildren |
||
53 | ); |
||
54 | $this->assertCount( |
||
55 | 1, |
||
56 | // Sub-person |
||
57 | $result->xmlChildren[0]->xmlChildren[0]->xmlChildren |
||
58 | ); |
||
59 | $this->assertInstanceOf( |
||
60 | Person::class, |
||
61 | $subPerson = $result->xmlChildren[0]->xmlChildren[0]->xmlChildren[0] |
||
62 | ); |
||
63 | $this->assertEquals( |
||
64 | 'Adam', |
||
65 | $subPerson->name |
||
66 | ); |
||
67 | $this->assertEquals( |
||
68 | 'Morgan', |
||
69 | $subPerson->surname |
||
70 | ); |
||
71 | } |
||
72 | |||
102 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.