Passed
Push — master ( ef4e7c...adf913 )
by Stephen
01:13 queued 13s
created

Exporter::localPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Sfneal\ViewExport\Support;
4
5
use Illuminate\Support\Facades\Storage;
6
use Sfneal\Helpers\Aws\S3\S3;
7
8
class Exporter
9
{
10
    // todo: add ability to store locally
11
    // todo: fix docstrings to not be pdf specific
12
13
    /**
14
     * @var string|null local file path
15
     */
16
    protected $localPath;
17
18
    /**
19
     * @var string|null AWS S3 file path
20
     */
21
    protected $uploadPath;
22
23
    /**
24
     * @var string|null AWS S3 file URL
25
     */
26
    protected $url;
27
28
    /**
29
     * @var string|null
30
     */
31
    protected $output;
32
33
    /**
34
     * Upload a rendered PDF to an AWS S3 file store.
35
     *
36
     * @param string $path
37
     * @return $this
38
     */
39
    public function upload(string $path): self
40
    {
41
        $this->uploadPath = $path;
42
43
        // todo: add use of Storage
44
        $this->url = (new S3($path))->upload_raw($this->output());
0 ignored issues
show
Bug introduced by
It seems like $this->output() can also be of type null; however, parameter $file_contents of Sfneal\Helpers\Aws\S3\S3::upload_raw() does only seem to accept string, 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

44
        $this->url = (new S3($path))->upload_raw(/** @scrutinizer ignore-type */ $this->output());
Loading history...
45
46
        return $this;
47
    }
48
49
    /**
50
     * Store a rendered PDF on the local file system.
51
     *
52
     * @param string $path
53
     * @return $this
54
     */
55
    public function store(string $path): self
56
    {
57
        $this->localPath = $path;
58
        Storage::put($path, $this->output());
59
60
        return $this;
61
    }
62
63
    /**
64
     * Retrieve the PDF's output.
65
     *
66
     * @return string|null
67
     */
68
    public function output(): ?string
69
    {
70
        return $this->output;
71
    }
72
73
    /**
74
     * Retrieve the PDF's AWS S3 path if available or the local file path.
75
     *
76
     * @return string|null
77
     */
78
    public function path(): ?string
79
    {
80
        return $this->uploadPath() ?? $this->localPath();
81
    }
82
83
    /**
84
     * Retrieve the PDF's AWS S3 path.
85
     *
86
     * @return string|null
87
     */
88
    public function uploadPath(): ?string
89
    {
90
        return $this->uploadPath;
91
    }
92
93
    /**
94
     * Retrieve the PDF's local file path.
95
     *
96
     * @return string|null
97
     */
98
    public function localPath(): ?string
99
    {
100
        return $this->localPath;
101
    }
102
103
    /**
104
     * Retrieve the PDF's AWS S3 url.
105
     *
106
     * @return string|null
107
     */
108
    public function url(): ?string
109
    {
110
        return $this->url;
111
    }
112
}
113