Completed
Push — master ( 8c9c54...6d4889 )
by Elf
44:15
created

AssetHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 44
ccs 0
cts 18
cp 0
rs 10
wmc 5
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilesystem() 0 4 1
A getAssetUrl() 0 12 3
A getFilesystemDisk() 0 4 1
1
<?php
2
3
namespace ElfSundae\Support\Traits;
4
5
use Illuminate\Support\Facades\Storage;
6
7
trait AssetHelper
8
{
9
    /**
10
     * Get Filesystem instance for the given identifier.
11
     *
12
     * @param  string|null  $identifier
13
     * @return \Illuminate\Contracts\Filesystem\Filesystem
14
     */
15
    public function getFilesystem($identifier = null)
16
    {
17
        return Storage::disk($this->getFilesystemDisk($identifier));
18
    }
19
20
    /**
21
     * Get asset URL.
22
     *
23
     * @param  string  $path
24
     * @param  string|null  $identifier
25
     * @return string|null
26
     */
27
    protected function getAssetUrl($path, $identifier = null)
28
    {
29
        if (empty($path)) {
30
            return;
31
        }
32
33
        if (filter_var($path, FILTER_VALIDATE_URL) !== false) {
34
            return $path;
35
        }
36
37
        return $this->getFilesystem($identifier)->url($path);
38
    }
39
40
    /**
41
     * Get disk name for filesystem.
42
     *
43
     * @param  string|null  $identifier
44
     * @return string|null
45
     */
46
    protected function getFilesystemDisk($identifier = null)
47
    {
48
        return 'public';
49
    }
50
}
51