Conditions | 1 |
Paths | 1 |
Total Lines | 64 |
Code Lines | 43 |
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 |
||
31 | public function testToXML() |
||
32 | { |
||
33 | $data = array( |
||
34 | 'infoDistributed' => array( |
||
35 | '@attributes' => array( |
||
36 | 'language' => 'EN', |
||
37 | ), |
||
38 | 'mobilePhone' => '0495151689', |
||
39 | ), |
||
40 | ); |
||
41 | |||
42 | $expectedDocument = self::createDomDocument(); |
||
43 | $infoDistributed = $expectedDocument->createElement('infoDistributed'); |
||
44 | $infoDistributed->setAttribute('language', $data['infoDistributed']['@attributes']['language']); |
||
45 | $infoDistributed->appendChild( |
||
46 | $expectedDocument->createElement( |
||
47 | 'mobilePhone', |
||
48 | $data['infoDistributed']['mobilePhone'] |
||
49 | ) |
||
50 | ); |
||
51 | $expectedDocument->appendChild($infoDistributed); |
||
52 | |||
53 | $actualDocument = self::createDomDocument(); |
||
54 | $messaging = new Messaging( |
||
55 | 'infoDistributed', |
||
56 | $data['infoDistributed']['@attributes']['language'], |
||
57 | null, |
||
58 | $data['infoDistributed']['mobilePhone'] |
||
59 | ); |
||
60 | $actualDocument->appendChild( |
||
61 | $messaging->toXML($actualDocument, null) |
||
62 | ); |
||
63 | $this->assertEquals($expectedDocument, $actualDocument); |
||
64 | |||
65 | $data = array( |
||
66 | 'infoNextDay' => array( |
||
67 | '@attributes' => array( |
||
68 | 'language' => 'EN', |
||
69 | ), |
||
70 | 'emailAddress' => '[email protected]', |
||
71 | ), |
||
72 | ); |
||
73 | |||
74 | $expectedDocument = self::createDomDocument(); |
||
75 | $infoNextDay = $expectedDocument->createElement('infoNextDay'); |
||
76 | $infoNextDay->setAttribute('language', $data['infoNextDay']['@attributes']['language']); |
||
77 | $infoNextDay->appendChild( |
||
78 | $expectedDocument->createElement( |
||
79 | 'emailAddress', |
||
80 | $data['infoNextDay']['emailAddress'] |
||
81 | ) |
||
82 | ); |
||
83 | $expectedDocument->appendChild($infoNextDay); |
||
84 | |||
85 | $actualDocument = self::createDomDocument(); |
||
86 | $messaging = new Messaging( |
||
87 | 'infoNextDay', |
||
88 | $data['infoNextDay']['@attributes']['language'], |
||
89 | $data['infoNextDay']['emailAddress'] |
||
90 | ); |
||
91 | $actualDocument->appendChild( |
||
92 | $messaging->toXML($actualDocument, null) |
||
93 | ); |
||
94 | $this->assertEquals($expectedDocument, $actualDocument); |
||
95 | } |
||
142 |