Code Duplication    Length = 34-35 lines in 2 locations

src/ReportingCloud.php 2 locations

@@ 287-320 (lines=34) @@
284
     *
285
     * @return bool
286
     */
287
    public function uploadTemplate($templateFilename)
288
    {
289
        $ret = false;
290
291
        StaticValidator::execute($templateFilename, 'TemplateExtension');
292
        StaticValidator::execute($templateFilename, 'FileExists');
293
294
        $templateFilename = realpath($templateFilename);
295
        $templateName     = basename($templateFilename);
296
297
        $query = [
298
            'templateName' => $templateName,
299
        ];
300
301
        $body = file_get_contents($templateFilename);
302
        $body = base64_encode($body);
303
        $body = json_encode($body);
304
305
        $options = [
306
            RequestOptions::HEADERS => $this->headers(),
307
            RequestOptions::QUERY   => $query,
308
            RequestOptions::BODY    => $body,
309
        ];
310
311
        $response = $this->request('POST', $this->uri('/templates/upload'), $options);
312
313
        if ($response instanceof Response) {
314
            if (201 === $response->getStatusCode()) {
315
                $ret = true;
316
            }
317
        }
318
319
        return $ret;
320
    }
321
322
    /**
323
     * Convert a document on the local file system to a different format
@@ 332-366 (lines=35) @@
329
     *
330
     * @return null|resource
331
     */
332
    public function convertDocument($documentFilename, $returnFormat)
333
    {
334
        $ret = null;
335
336
        StaticValidator::execute($documentFilename, 'DocumentExtension');
337
        StaticValidator::execute($documentFilename, 'FileExists');
338
        StaticValidator::execute($returnFormat    , 'ReturnFormat');
339
340
        $query = [
341
            'returnFormat' => $returnFormat,
342
        ];
343
344
        $documentFilename = realpath($documentFilename);
345
346
        $body = file_get_contents($documentFilename);
347
        $body = base64_encode($body);
348
        $body = json_encode($body);
349
350
        $options = [
351
            RequestOptions::HEADERS => $this->headers(),
352
            RequestOptions::QUERY   => $query,
353
            RequestOptions::BODY    => $body,
354
        ];
355
356
        $response = $this->request('POST', $this->uri('/document/convert'), $options);
357
358
        if ($response instanceof Response) {
359
            if (200 === $response->getStatusCode()) {
360
                $body = (string) $response->getBody();
361
                $ret  = base64_decode($body);
362
            }
363
        }
364
365
        return $ret;
366
    }
367
368
    /**
369
     * Merge data into a template and return an array of binary data.