Code Duplication    Length = 33-34 lines in 2 locations

src/ReportingCloud.php 2 locations

@@ 287-319 (lines=33) @@
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::QUERY => $query,
307
            RequestOptions::BODY  => $body,
308
        ];
309
310
        $response = $this->request('POST', $this->uri('/templates/upload'), $options);
311
312
        if ($response instanceof Response) {
313
            if (201 === $response->getStatusCode()) {
314
                $ret = true;
315
            }
316
        }
317
318
        return $ret;
319
    }
320
321
    /**
322
     * Convert a document on the local file system to a different format
@@ 331-364 (lines=34) @@
328
     *
329
     * @return null|resource
330
     */
331
    public function convertDocument($documentFilename, $returnFormat)
332
    {
333
        $ret = null;
334
335
        StaticValidator::execute($documentFilename, 'DocumentExtension');
336
        StaticValidator::execute($documentFilename, 'FileExists');
337
        StaticValidator::execute($returnFormat    , 'ReturnFormat');
338
339
        $query = [
340
            'returnFormat' => $returnFormat,
341
        ];
342
343
        $documentFilename = realpath($documentFilename);
344
345
        $body = file_get_contents($documentFilename);
346
        $body = base64_encode($body);
347
        $body = json_encode($body);
348
349
        $options = [
350
            RequestOptions::QUERY => $query,
351
            RequestOptions::BODY  => $body,
352
        ];
353
354
        $response = $this->request('POST', $this->uri('/document/convert'), $options);
355
356
        if ($response instanceof Response) {
357
            if (200 === $response->getStatusCode()) {
358
                $body = (string) $response->getBody();
359
                $ret  = base64_decode($body);
360
            }
361
        }
362
363
        return $ret;
364
    }
365
366
    /**
367
     * Merge data into a template and return an array of binary data.