DownloadFileAction::headers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace MagicLink\Actions;
4
5
use Illuminate\Support\Facades\Storage;
6
7
class DownloadFileAction extends ActionAbstract
8
{
9
    protected $path;
10
11
    protected $name;
12
13
    protected $headers;
14
15
    protected $disk;
16
17
    /**
18
     * Constructor to action.
19
     *
20
     * @return void
21
     */
22
    public function __construct(string $path, ?string $name = null, array $headers = [])
23
    {
24
        $this->path = $path;
25
        if (! is_null($name)) {
26
            $this->name($name);
27
        }
28
        $this->headers($headers);
29
    }
30
31
    public function name(string $name): self
32
    {
33
        $this->name = $name;
34
35
        return $this;
36
    }
37
38
    public function disk(?string $disk): self
39
    {
40
        $this->disk = $disk;
41
42
        return $this;
43
    }
44
45
    public function headers(array $headers): self
46
    {
47
        $this->headers = $headers;
48
49
        return $this;
50
    }
51
52
    /**
53
     * Execute Action.
54
     */
55
    public function run()
56
    {
57
        return Storage::disk($this->disk)->download($this->path, $this->name, $this->headers);
58
    }
59
}
60