Code Duplication    Length = 28-29 lines in 2 locations

src/Generation/Handler/BodyHandler.php 2 locations

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