HasMediaFilesystemTrait::getMediaFilesystemDisk()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace ByTIC\MediaLibrary\HasMedia\Traits;
4
5
use Nip\Filesystem\FileDisk;
6
use Nip\Utility\Str;
7
8
/**
9
 * Trait HasMediaFilesystemTrait.
10
 */
11
trait HasMediaFilesystemTrait
12
{
13
    /**
14
     * Get the default files disk instance for current model.
15
     *
16
     * @return FileDisk
17
     */
18
    public function getMediaFilesystemDisk($collection = null)
19
    {
20
        return app('filesystem')->disk($this->getMediaFilesystemDiskName($collection));
21
    }
22
23
    /**
24
     * @return string
25
     */
26
    public function getMediaFilesystemDiskName($collection = null)
27
    {
28
        $methodBase = 'generateMediaFilesystemDiskName';
29
        $method = $methodBase . Str::camel($collection);
30
        if (method_exists($this, $method)) {
31
            return $this->{$method}($collection);
32
        }
33
        if (method_exists($this, $methodBase)) {
34
            return $this->{$methodBase}($collection);
35
        }
36
        return 'public';
37
    }
38
}
39