Conditions | 1 |
Paths | 1 |
Total Lines | 100 |
Code Lines | 63 |
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 |
||
48 | public function formatTestData() |
||
49 | { |
||
50 | $date = new DateTime(); |
||
51 | return [ |
||
52 | [ |
||
53 | new JsonFormat(), |
||
54 | [ |
||
55 | 'key' => 'value', |
||
56 | 'int' => 1, |
||
57 | 'float' => 2.5, |
||
58 | 'bool' => true, |
||
59 | 'null' => null, |
||
60 | 'array' => ['a', 'b', 'c'], |
||
61 | 'object' => (object) ['a' => 1], |
||
62 | 'date' => $date, |
||
63 | ], |
||
64 | '{"key":"value","int":1,"float":2.5,"bool":true,"null":null,"array":["a","b","c"],"object":{"a":1},"date":"' . $date->format('Y-m-d H:i:s') . '"}', |
||
65 | '[', |
||
66 | ",\n", |
||
67 | "]\n", |
||
68 | ], |
||
69 | [ |
||
70 | new JsonFormat([ |
||
71 | JsonFormat::OPTION_ENCODE_OPTIONS => JSON_PRETTY_PRINT, |
||
72 | JsonFormat::OPTION_FILE_TYPE => JsonFormat::JSON_FILE_TYPE_SINGLE_BLOCK, |
||
73 | ]), |
||
74 | [ |
||
75 | 'key' => 'value', |
||
76 | 'int' => 1, |
||
77 | 'float' => 2.5, |
||
78 | 'bool' => true, |
||
79 | 'null' => null, |
||
80 | 'array' => ['a', 'b', 'c'], |
||
81 | 'object' => (object) ['a' => 1], |
||
82 | 'date' => $date, |
||
83 | ], |
||
84 | <<<JSON |
||
85 | { |
||
86 | "key": "value", |
||
87 | "int": 1, |
||
88 | "float": 2.5, |
||
89 | "bool": true, |
||
90 | "null": null, |
||
91 | "array": [ |
||
92 | "a", |
||
93 | "b", |
||
94 | "c" |
||
95 | ], |
||
96 | "object": { |
||
97 | "a": 1 |
||
98 | }, |
||
99 | "date": "{$date->format('Y-m-d H:i:s')}" |
||
100 | } |
||
101 | JSON |
||
102 | , |
||
103 | '[', |
||
104 | ",\n", |
||
105 | "]\n", |
||
106 | ], |
||
107 | [ |
||
108 | new JsonFormat([ |
||
109 | JsonFormat::OPTION_FILE_TYPE => JsonFormat::JSON_FILE_TYPE_EACH_LINE, |
||
110 | ]), |
||
111 | [ |
||
112 | 'key' => 'value', |
||
113 | 'int' => 1, |
||
114 | 'float' => 2.5, |
||
115 | 'bool' => true, |
||
116 | 'null' => null, |
||
117 | 'array' => ['a', 'b', 'c'], |
||
118 | 'object' => (object) ['a' => 1], |
||
119 | 'date' => $date, |
||
120 | ], |
||
121 | '{"key":"value","int":1,"float":2.5,"bool":true,"null":null,"array":["a","b","c"],"object":{"a":1},"date":"' . $date->format('Y-m-d H:i:s') . '"}', |
||
122 | '', |
||
123 | "\n", |
||
124 | '', |
||
125 | ], |
||
126 | [ |
||
127 | new JsonFormat([ |
||
128 | JsonFormat::OPTION_FILE_TYPE => JsonFormat::JSON_FILE_TYPE_EACH_LINE, |
||
129 | JsonFormat::OPTION_ENCODE_OPTIONS => JSON_PRETTY_PRINT, |
||
130 | ]), |
||
131 | [ |
||
132 | 'key' => 'value', |
||
133 | 'int' => 1, |
||
134 | 'float' => 2.5, |
||
135 | 'bool' => true, |
||
136 | 'null' => null, |
||
137 | 'array' => ['a', 'b', 'c'], |
||
138 | 'object' => (object) ['a' => 1], |
||
139 | 'date' => $date, |
||
140 | ], |
||
141 | '{"key":"value","int":1,"float":2.5,"bool":true,"null":null,"array":["a","b","c"],"object":{"a":1},"date":"' . $date->format('Y-m-d H:i:s') . '"}', |
||
142 | '', |
||
143 | "\n", |
||
144 | '', |
||
145 | ], |
||
146 | ]; |
||
147 | } |
||
148 | |||
160 |