Code Duplication    Length = 28-29 lines in 2 locations

src/Generation/Handler/BodyHandler.php 2 locations

@@ 105-132 (lines=28) @@
102
     * @return null
103
     * @throws LogicException
104
     */
105
    private function createBodyJson(HandlerContext $context)
106
    {
107
        $body = $context->annotations()->getBody();
108
109
        // json encode arrays
110
        if ($context->annotations()->isBodyArray()) {
111
            $context->body()->add('$body = json_encode(%s);', $body);
112
113
            return null;
114
        }
115
116
        // if parts exist, json encode the parts
117
        if (null !== $context->annotations()->getBodyParts()) {
118
            $context->body()->add('$body = json_encode(%s);', $context->printer()->printArray($context->annotations()->getBodyParts()));
119
120
            return null;
121
        }
122
123
        // if it's an object, serialize it unless it implements \JsonSerializable
124
        if ($context->annotations()->isBodyJsonSerializable()) {
125
            $context->body()->add('$body = json_encode(%s);', $body);
126
127
            return null;
128
        }
129
130
        $this->createContext($context, '$bodySerializationContext');
131
        $context->body()->add('$body = $this->serializer->serialize(%s, "json", $bodySerializationContext);', $body);
132
    }
133
134
    /**
135
     * Create body as array first
@@ 141-169 (lines=29) @@
138
     * @return null
139
     * @throws LogicException
140
     */
141
    private function createBodyArray(HandlerContext $context)
142
    {
143
        $body = $context->annotations()->getBody();
144
145
        // if it's already an array, set to variable
146
        if ($context->annotations()->isBodyArray()) {
147
            $context->body()->add('$bodyArray = %s;', $body);
148
149
            return null;
150
        }
151
152
        // if parts exist, set to variable
153
        if (null !== $context->annotations()->getBodyParts()) {
154
            $context->body()->add('$bodyArray = %s;', $context->printer()->printArray($context->annotations()->getBodyParts()));
155
156
            return null;
157
        }
158
159
        // if it implements \JsonSerializable, call jsonSerialize() to get array
160
        if ($context->annotations()->isBodyJsonSerializable()) {
161
            $context->body()->add('$bodyArray = %s->jsonSerialize();', $body);
162
163
            return;
164
        }
165
166
        // otherwise, convert to array
167
        $this->createContext($context, '$bodySerializationContext');
168
        $context->body()->add('$bodyArray = $this->serializer->toArray(%s, $bodySerializationContext);', $body);
169
    }
170
171
    /**
172
     * Create serialization context