HasMediaFilesystemTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 26
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMediaFilesystemDisk() 0 3 1
A getMediaFilesystemDiskName() 0 11 3
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