Conditions | 4 |
Paths | 4 |
Total Lines | 58 |
Code Lines | 44 |
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 | 'name' => 'Tijs Verkoyen', |
||
35 | 'company' => 'Sumo Coders', |
||
36 | 'address' => array( |
||
37 | 'streetName' => 'Afrikalaan', |
||
38 | 'number' => '289', |
||
39 | 'box' => '3', |
||
40 | 'postalCode' => '9000', |
||
41 | 'locality' => 'Gent', |
||
42 | 'countryCode' => 'BE', |
||
43 | ), |
||
44 | 'emailAddress' => '[email protected]', |
||
45 | 'phoneNumber' => '+32 9 395 02 51', |
||
46 | ); |
||
47 | |||
48 | $expectedDocument = self::createDomDocument(); |
||
49 | $sender = $expectedDocument->createElement('sender'); |
||
50 | foreach ($data as $key => $value) { |
||
51 | $key = 'common:' . $key; |
||
52 | if ($key == 'common:address') { |
||
53 | $address = $expectedDocument->createElement($key); |
||
54 | foreach ($value as $key2 => $value2) { |
||
55 | $key2 = 'common:' . $key2; |
||
56 | $address->appendChild( |
||
57 | $expectedDocument->createElement($key2, $value2) |
||
58 | ); |
||
59 | } |
||
60 | $sender->appendChild($address); |
||
61 | } else { |
||
62 | $sender->appendChild( |
||
63 | $expectedDocument->createElement($key, $value) |
||
|
|||
64 | ); |
||
65 | } |
||
66 | } |
||
67 | $expectedDocument->appendChild($sender); |
||
68 | |||
69 | $actualDocument = self::createDomDocument(); |
||
70 | $address = new Address( |
||
71 | $data['address']['streetName'], |
||
72 | $data['address']['number'], |
||
73 | $data['address']['box'], |
||
74 | $data['address']['postalCode'], |
||
75 | $data['address']['locality'], |
||
76 | $data['address']['countryCode'] |
||
77 | ); |
||
78 | $sender = new Sender(); |
||
79 | $sender->setName($data['name']); |
||
80 | $sender->setCompany($data['company']); |
||
81 | $sender->setAddress($address); |
||
82 | $sender->setEmailAddress($data['emailAddress']); |
||
83 | $sender->setPhoneNumber($data['phoneNumber']); |
||
84 | $actualDocument->appendChild( |
||
85 | $sender->toXML($actualDocument, null) |
||
86 | ); |
||
87 | |||
88 | $this->assertSame($expectedDocument->saveXML(), $actualDocument->saveXML()); |
||
89 | } |
||
120 |