GenerateStorableFile   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 2
eloc 7
c 3
b 0
f 1
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 7 1
A __construct() 0 3 1
1
<?php
2
3
namespace Gurgentil\LaravelStorable\Services;
4
5
use Gurgentil\LaravelStorable\Contracts\Storable;
6
use Illuminate\Support\Facades\Config;
7
use Illuminate\Support\Facades\Storage;
8
9
class GenerateStorableFile
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $disk;
15
16
    /**
17
     * GenerateStorableFile constructor.
18
     *
19
     * @param string|null $disk
20
     */
21
    public function __construct(?string $disk = null)
22
    {
23
        $this->disk = $disk ?? Config::get('storable.disk');
24
    }
25
26
    /**
27
     * Write file to storage.
28
     *
29
     * @param Storable $storable
30
     */
31
    public function handle(Storable $storable): void
32
    {
33
        $path = $storable->getFilePath();
34
        $contents = $storable->getContents();
35
36
        Storage::disk($this->disk)
37
            ->put($path, $contents);
38
    }
39
}
40