Passed
Pull Request — master (#33)
by Cesar
05:13
created

DownloadFileAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 11
c 1
b 0
f 1
dl 0
loc 38
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A disk() 0 5 1
A run() 0 3 1
1
<?php
2
3
namespace MagicLink\Actions;
4
5
use Illuminate\Support\Facades\Storage;
6
7
class DownloadFileAction implements ActionInterface
8
{
9
    protected $path;
10
11
    protected $name;
12
13
    protected $headers;
14
15
    protected $disk;
16
17
    /**
18
     * Constructor to action.
19
     *
20
     * @param  string  $path
21
     * @param  string|null  $name
22
     * @param  array  $headers
23
     * @return void
24
     */
25
    public function __construct(string $path, ?string $name = null, array $headers = [])
26
    {
27
        $this->path = $path;
28
        $this->name = $name;
29
        $this->headers = $headers;
30
    }
31
32
    public function disk(?string $disk): self
33
    {
34
        $this->disk = $disk;
35
36
        return $this;
37
    }
38
39
    /**
40
     * Execute Action.
41
     */
42
    public function run()
43
    {
44
        return Storage::disk($this->disk)->download($this->path, $this->name, $this->headers);
45
    }
46
}
47