Test Failed
Pull Request — master (#36)
by Stephen
03:30
created

CloudStorage::enableStreaming()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Sfneal\Helpers\Aws\S3\Utils;
4
5
use Illuminate\Contracts\Filesystem\Filesystem;
6
use Illuminate\Filesystem\FilesystemAdapter;
7
use Illuminate\Support\Facades\Storage;
8
9
class CloudStorage
10
{
11
    /**
12
     * @var string AWS S3 file key
13
     */
14
    protected $s3Key;
15
16
    /**
17
     * @var string Storage S3 cloud disk name
18
     */
19
    protected $disk;
20
21
    /**
22
     * @var bool Enable/disable upload & download streaming
23
     */
24
    protected $streaming;
25
26
    /**
27
     * S3 constructor.
28
     *
29
     * @param string $s3Key
30
     */
31
    public function __construct(string $s3Key)
32
    {
33
        $this->s3Key = $s3Key;
34
        $this->disk = config('filesystem.cloud', 's3');
35
        $this->streaming = config('s3-helpers.streaming', true);
36
    }
37
38
    /**
39
     * Retrieve a Filesystem instance for the specified disk.
40
     *
41
     * @return Filesystem|FilesystemAdapter
42
     */
43
    protected function storageDisk(): FilesystemAdapter
44
    {
45
        return Storage::disk($this->disk);
46
    }
47
48
    /**
49
     * Determine if upload/download streaming is enabled.
50
     *
51
     * @return bool
52
     */
53
    protected function isStreamingEnabled(): bool
54
    {
55
        return $this->streaming;
56
    }
57
58
    /**
59
     * Retrieve the S3 key (useful in conjunctions with `autocompletePath()` method).
60
     *
61
     * @return string
62
     */
63
    public function getKey(): string
64
    {
65
        return $this->s3Key;
66
    }
67
68
    /**
69
     * Set the filesystem disk.
70
     *
71
     * @param string $disk
72
     * @return $this
73
     */
74
    public function setDisk(string $disk): self
75
    {
76
        $this->disk = $disk;
77
78
        return $this;
79
    }
80
81
    /**
82
     * Enable upload/download streaming regardless of config setting.
83
     *
84
     * @return $this
85
     */
86
    public function enableStreaming(): self
87
    {
88
        $this->streaming = true;
89
90
        return $this;
91
    }
92
93
    /**
94
     * Disable upload/download streaming regardless of config setting.
95
     *
96
     * @return $this
97
     */
98
    public function disableStreaming(): self
99
    {
100
        $this->streaming = false;
101
102
        return $this;
103
    }
104
}
105