Conditions | 1 |
Paths | 1 |
Total Lines | 85 |
Code Lines | 45 |
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 |
||
14 | public function addArrayAsChildrenDataProvider() |
||
15 | { |
||
16 | $data = []; |
||
17 | |||
18 | // Basic test |
||
19 | $array = [ |
||
20 | 'child' => 123 |
||
21 | ]; |
||
22 | $expectedChildXml = '<child>123</child>'; |
||
23 | $data[] = [$array, $expectedChildXml]; |
||
24 | |||
25 | // Attributes |
||
26 | $array = [ |
||
27 | 'child' => [ |
||
28 | '@attributes' => [ |
||
29 | 'id' => '1', |
||
30 | 'name' => 'foo' |
||
31 | ] |
||
32 | ] |
||
33 | ]; |
||
34 | $expectedChildXml = '<child id="1" name="foo"/>'; |
||
35 | $data[] = [$array, $expectedChildXml]; |
||
36 | |||
37 | // Attibute with value |
||
38 | $array = [ |
||
39 | 'child' => [ |
||
40 | '@attributes' => [ |
||
41 | 'id' => '1' |
||
42 | ], |
||
43 | '@value' => 123 |
||
44 | ] |
||
45 | ]; |
||
46 | $expectedChildXml = '<child id="1">123</child>'; |
||
47 | $data[] = [$array, $expectedChildXml]; |
||
48 | |||
49 | // Multiple children |
||
50 | $array = [ |
||
51 | 'child1' => 111, |
||
52 | 'child2' => 222 |
||
53 | ]; |
||
54 | $expectedChildXml = '<child1>111</child1><child2>222</child2>'; |
||
55 | $data[] = [$array, $expectedChildXml]; |
||
56 | |||
57 | // Multiple children with the name node name |
||
58 | $array = [ |
||
59 | 'child' => [ |
||
60 | [ |
||
61 | 'item' => 111 |
||
62 | ], |
||
63 | [ |
||
64 | 'item' => 222 |
||
65 | ] |
||
66 | ] |
||
67 | ]; |
||
68 | $expectedChildXml = '<child><item>111</item></child><child><item>222</item></child>'; |
||
69 | $data[] = [$array, $expectedChildXml]; |
||
70 | |||
71 | // Ignore empty value |
||
72 | $array = [ |
||
73 | 'child1' => 111, |
||
74 | 'child2' => '' |
||
75 | ]; |
||
76 | $expectedChildXml = '<child1>111</child1>'; |
||
77 | $data[] = [$array, $expectedChildXml]; |
||
78 | |||
79 | // Complex example |
||
80 | $array = [ |
||
81 | 'child1' => 111, |
||
82 | 'child2' => [ |
||
83 | 'item' => [ |
||
84 | [ |
||
85 | '@attributes' => [ |
||
86 | 'id' => 123 |
||
87 | ] |
||
88 | ], |
||
89 | [ |
||
90 | 'property' => 456 |
||
91 | ] |
||
92 | ] |
||
93 | ] |
||
94 | ]; |
||
95 | $expectedChildXml = '<child1>111</child1><child2><item id="123"/><item><property>456</property></item></child2>'; |
||
96 | $data[] = [$array, $expectedChildXml]; |
||
97 | |||
98 | return $data; |
||
99 | } |
||
142 |