| Conditions | 10 |
| Paths | 9 |
| Total Lines | 48 |
| Code Lines | 26 |
| 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 |
||
| 76 | * @param JsonWritable $writer |
||
| 77 | * @param JsonElement $value |
||
| 78 | * @return void |
||
| 79 | */ |
||
| 80 | 10 | public function write(JsonWritable $writer, $value): void |
|
| 81 | { |
||
| 82 | 10 | if (null === $value || $value->isJsonNull()) { |
|
| 83 | 3 | $writer->writeNull(); |
|
| 84 | |||
| 85 | 3 | return; |
|
| 86 | } |
||
| 87 | |||
| 88 | 8 | if ($value->isJsonObject()) { |
|
| 89 | 2 | $writer->beginObject(); |
|
| 90 | 2 | foreach ($value->asJsonObject() as $key => $element) { |
|
| 91 | 2 | $writer->name($key); |
|
| 92 | 2 | $this->write($writer, $element); |
|
| 93 | } |
||
| 94 | 2 | $writer->endObject(); |
|
| 95 | |||
| 96 | 2 | return; |
|
| 97 | } |
||
| 98 | |||
| 99 | 8 | if ($value->isJsonArray()) { |
|
| 100 | 2 | $writer->beginArray(); |
|
| 101 | 2 | foreach ($value->asJsonArray() as $element) { |
|
| 102 | 2 | $this->write($writer, $element); |
|
| 103 | } |
||
| 104 | 2 | $writer->endArray(); |
|
| 105 | |||
| 106 | 2 | return; |
|
| 107 | } |
||
| 108 | |||
| 109 | 8 | if ($value->isInteger()) { |
|
| 110 | 1 | $writer->writeInteger($value->asInteger()); |
|
| 111 | |||
| 112 | 1 | return; |
|
| 113 | } |
||
| 114 | |||
| 115 | 7 | if ($value->isFloat()) { |
|
| 116 | 1 | $writer->writeFloat($value->asFloat()); |
|
| 117 | |||
| 118 | 1 | return; |
|
| 119 | } |
||
| 120 | |||
| 121 | 6 | if ($value->isBoolean()) { |
|
| 122 | 2 | $writer->writeBoolean($value->asBoolean()); |
|
| 123 | |||
| 124 | 2 | return; |
|
| 130 |