| Conditions | 1 |
| Paths | 1 |
| Total Lines | 177 |
| Code Lines | 81 |
| 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 |
||
| 47 | public function parseJsonData() |
||
| 48 | { |
||
| 49 | return [ |
||
| 50 | [ |
||
| 51 | new JsonFormat(), |
||
| 52 | <<<JSON |
||
| 53 | [ |
||
| 54 | { |
||
| 55 | "name": "value", |
||
| 56 | "number": 1.2, |
||
| 57 | "bool": true, |
||
| 58 | "null": null, |
||
| 59 | "thing": { |
||
| 60 | "hi": "there" |
||
| 61 | }, |
||
| 62 | "array": [ |
||
| 63 | "a", |
||
| 64 | "1" |
||
| 65 | ] |
||
| 66 | }, |
||
| 67 | { |
||
| 68 | "other": "stuff" |
||
| 69 | } |
||
| 70 | ] |
||
| 71 | JSON |
||
| 72 | , |
||
| 73 | [ |
||
| 74 | (object) [ |
||
| 75 | 'name' => 'value', |
||
| 76 | 'number' => 1.2, |
||
| 77 | 'bool' => true, |
||
| 78 | 'null' => null, |
||
| 79 | 'thing' => (object) [ |
||
| 80 | 'hi' => 'there', |
||
| 81 | ], |
||
| 82 | 'array' => ['a', '1'], |
||
| 83 | ], |
||
| 84 | (object) [ |
||
| 85 | 'other' => 'stuff', |
||
| 86 | ], |
||
| 87 | ], |
||
| 88 | ], |
||
| 89 | [ |
||
| 90 | new JsonFormat([ |
||
| 91 | JsonFormat::OPTION_DECODE_ASSOC => true, |
||
| 92 | ]), |
||
| 93 | <<<JSON |
||
| 94 | [ |
||
| 95 | { |
||
| 96 | "name": "value\\nstuff", |
||
| 97 | "number": 1.2, |
||
| 98 | "bool": true, |
||
| 99 | "null": null, |
||
| 100 | "thing": { |
||
| 101 | "hi": "there" |
||
| 102 | }, |
||
| 103 | "array": [ |
||
| 104 | "a", |
||
| 105 | "1" |
||
| 106 | ] |
||
| 107 | }, |
||
| 108 | { |
||
| 109 | "other": "stuff" |
||
| 110 | } |
||
| 111 | ] |
||
| 112 | JSON |
||
| 113 | , |
||
| 114 | [ |
||
| 115 | [ |
||
| 116 | 'name' => "value\nstuff", |
||
| 117 | 'number' => 1.2, |
||
| 118 | 'bool' => true, |
||
| 119 | 'null' => null, |
||
| 120 | 'thing' => [ |
||
| 121 | 'hi' => 'there', |
||
| 122 | ], |
||
| 123 | 'array' => ['a', '1'], |
||
| 124 | ], |
||
| 125 | [ |
||
| 126 | 'other' => 'stuff', |
||
| 127 | ], |
||
| 128 | ], |
||
| 129 | ], |
||
| 130 | [ |
||
| 131 | new JsonFormat([ |
||
| 132 | JsonFormat::OPTION_FILE_TYPE => JsonFormat::JSON_FILE_TYPE_EACH_LINE, |
||
| 133 | ]), |
||
| 134 | <<<JSON |
||
| 135 | {"name": "value\\nline","number": 1.2,"bool": true,"null": null,"thing": {"hi": "there"},"array": ["a","1"]} |
||
| 136 | {"other": "stuff"} |
||
| 137 | JSON |
||
| 138 | , |
||
| 139 | [ |
||
| 140 | (object) [ |
||
| 141 | 'name' => "value\nline", |
||
| 142 | 'number' => 1.2, |
||
| 143 | 'bool' => true, |
||
| 144 | 'null' => null, |
||
| 145 | 'thing' => (object) [ |
||
| 146 | 'hi' => 'there', |
||
| 147 | ], |
||
| 148 | 'array' => ['a', '1'], |
||
| 149 | ], |
||
| 150 | (object) [ |
||
| 151 | 'other' => 'stuff', |
||
| 152 | ], |
||
| 153 | ], |
||
| 154 | ], |
||
| 155 | [ |
||
| 156 | new JsonFormat([ |
||
| 157 | JsonFormat::OPTION_FILE_TYPE => JsonFormat::JSON_FILE_TYPE_EACH_LINE, |
||
| 158 | JsonFormat::OPTION_IGNORE_BLANK_LINES => true, |
||
| 159 | ]), |
||
| 160 | <<<JSON |
||
| 161 | |||
| 162 | {"name": "value\\nline","number": 1.2,"bool": true,"null": null,"thing": {"hi": "there"},"array": ["a","1"]} |
||
| 163 | |||
| 164 | |||
| 165 | |||
| 166 | {"other": "stuff"} |
||
| 167 | |||
| 168 | JSON |
||
| 169 | , |
||
| 170 | [ |
||
| 171 | (object) [ |
||
| 172 | 'name' => "value\nline", |
||
| 173 | 'number' => 1.2, |
||
| 174 | 'bool' => true, |
||
| 175 | 'null' => null, |
||
| 176 | 'thing' => (object) [ |
||
| 177 | 'hi' => 'there', |
||
| 178 | ], |
||
| 179 | 'array' => ['a', '1'], |
||
| 180 | ], |
||
| 181 | (object) [ |
||
| 182 | 'other' => 'stuff', |
||
| 183 | ], |
||
| 184 | ], |
||
| 185 | ], |
||
| 186 | [ |
||
| 187 | new JsonFormat([ |
||
| 188 | JsonFormat::OPTION_FILE_TYPE => JsonFormat::JSON_FILE_TYPE_EACH_LINE, |
||
| 189 | JsonFormat::OPTION_IGNORE_BLANK_LINES => false, |
||
| 190 | ]), |
||
| 191 | <<<JSON |
||
| 192 | |||
| 193 | {"name": "value\\nline","number": 1.2,"bool": true,"null": null,"thing": {"hi": "there"},"array": ["a","1"]} |
||
| 194 | |||
| 195 | |||
| 196 | |||
| 197 | {"other": "stuff"} |
||
| 198 | |||
| 199 | JSON |
||
| 200 | , |
||
| 201 | [ |
||
| 202 | null, |
||
| 203 | (object) [ |
||
| 204 | 'name' => "value\nline", |
||
| 205 | 'number' => 1.2, |
||
| 206 | 'bool' => true, |
||
| 207 | 'null' => null, |
||
| 208 | 'thing' => (object) [ |
||
| 209 | 'hi' => 'there', |
||
| 210 | ], |
||
| 211 | 'array' => ['a', '1'], |
||
| 212 | ], |
||
| 213 | null, |
||
| 214 | null, |
||
| 215 | null, |
||
| 216 | (object) [ |
||
| 217 | 'other' => 'stuff', |
||
| 218 | ], |
||
| 219 | null, |
||
| 220 | ], |
||
| 221 | ], |
||
| 222 | ]; |
||
| 223 | } |
||
| 224 | |||
| 263 |