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