Code Duplication    Length = 30-31 lines in 2 locations

src/ReportingCloud.php 2 locations

@@ 280-309 (lines=30) @@
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
        $json = file_get_contents($templateFilename);
295
        $json = base64_encode($json);
296
297
        $options = [
298
            RequestOptions::QUERY => $query,
299
            RequestOptions::JSON  => $json,
300
        ];
301
302
        $response = $this->request('POST', $this->uri('/templates/upload'), $options);
303
304
        if ($response instanceof Response && 201 === $response->getStatusCode()) {
305
            $ret = true;
306
        }
307
308
        return $ret;
309
    }
310
311
    /**
312
     * Convert a document on the local file system to a different format
@@ 321-351 (lines=31) @@
318
     *
319
     * @return null|resource
320
     */
321
    public function convertDocument($documentFilename, $returnFormat)
322
    {
323
        $ret = null;
324
325
        StaticValidator::execute($documentFilename, 'DocumentExtension');
326
        StaticValidator::execute($documentFilename, 'FileExists');
327
        StaticValidator::execute($returnFormat    , 'ReturnFormat');
328
329
        $query = [
330
            'returnFormat' => $returnFormat,
331
        ];
332
333
        $documentFilename = realpath($documentFilename);
334
335
        $json = file_get_contents($documentFilename);
336
        $json = base64_encode($json);
337
338
        $options = [
339
            RequestOptions::QUERY => $query,
340
            RequestOptions::JSON  => $json,
341
        ];
342
343
        $response = $this->request('POST', $this->uri('/document/convert'), $options);
344
345
        if ($response instanceof Response && 200 === $response->getStatusCode()) {
346
            $body = (string) $response->getBody();
347
            $ret  = base64_decode($body);
348
        }
349
350
        return $ret;
351
    }
352
353
    /**
354
     * Merge data into a template and return an array of binary data.