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