Code Duplication    Length = 21-26 lines in 2 locations

src/Traits/Rest.php 2 locations

@@ 104-124 (lines=21) @@
101
     * @return array|mixed
102
     * @throws RequestException
103
     */
104
    private function post(string $endpoint, array $body = [], $correlationId = null, bool $asJson = false)
105
    {
106
        if (is_null($correlationId) && $this->requireCorrelationId($endpoint)) {
107
            $correlationId = Uuid::uuid4()->toString();
108
        }
109
110
        $this->setHeaders([
111
            'API-Version' => $this->apiVersion,
112
            'x-correlation-id' => $correlationId
113
        ]);
114
115
        $bodyFormat = $asJson ? 'json' : 'form_params';
116
        $token = Auth::login()->getToken();
117
118
        return Http::withToken($token)
119
            ->withHeaders($this->headers)
120
            ->bodyFormat($bodyFormat)
121
            ->post($this->getFinalUrl($endpoint), $body)
122
            ->throw()
123
            ->json();
124
    }
125
126
    /**
127
     * @param string $endpoint
@@ 177-202 (lines=26) @@
174
     * @return array|mixed
175
     * @throws RequestException
176
     */
177
    private function patch(
178
        string $endpoint,
179
        array $body = [],
180
        $correlationId = null,
181
        bool $asJson = false
182
    ) {
183
        if (is_null($correlationId) && $this->requireCorrelationId($endpoint)) {
184
            $correlationId = Uuid::uuid4()->toString();
185
        }
186
187
        $this->setHeaders([
188
            'API-Version' => $this->apiVersion,
189
            'x-correlation-id' => $correlationId
190
        ]);
191
192
        $bodyFormat = $asJson ? 'json' : 'form_params';
193
        $token = Auth::login()->getToken();
194
195
        $request = Http::withToken($token)
196
            ->withHeaders($this->headers)
197
            ->bodyFormat($bodyFormat);
198
199
        return $request->patch($this->getFinalUrl($endpoint), $body)
200
            ->throw()
201
            ->json();
202
    }
203
204
    /**
205
     * Http delete method.