Code Duplication    Length = 31-32 lines in 2 locations

src/ReportingCloud.php 2 locations

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