Passed
Pull Request — master (#17)
by Stephen
12:58 queued 10:30
created

PdfExportAction::storeFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Sfneal\ViewExport\Pdf;
4
5
use Dompdf\Exception;
6
use Sfneal\Actions\AbstractAction;
7
8
class PdfExportAction extends AbstractAction
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $path;
14
15
    /**
16
     * @var string
17
     */
18
    protected $view;
19
20
    /**
21
     * @var array|null
22
     */
23
    protected $view_data;
24
25
    /**
26
     * CreatePdfFromViewAction constructor.
27
     *
28
     * @param string $path
29
     * @param string $view
30
     * @param array|null $view_data
31
     */
32
    public function __construct(string $path, string $view, array $view_data = [])
33
    {
34
        $this->path = $path;
35
        $this->view = $view;
36
        $this->view_data = $view_data;
37
    }
38
39
    /**
40
     * Create a PDF from a view & return its file path.
41
     *
42
     * @throws Exception
43
     * @return string
44
     */
45
    public function execute(): string
46
    {
47
        // Create & Render the PDF
48
        $exporter = PdfExportService::fromViewData($this->view, $this->view_data);
0 ignored issues
show
Bug introduced by
It seems like $this->view_data can also be of type null; however, parameter $viewData of Sfneal\ViewExport\Pdf\Pd...Service::fromViewData() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
        $exporter = PdfExportService::fromViewData($this->view, /** @scrutinizer ignore-type */ $this->view_data);
Loading history...
49
50
        // Upload the PDF to AWS S3
51
        $exporter->upload($this->path);
52
53
        // Return the path
54
        return $exporter->getPath();
55
    }
56
}
57