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

AssetHelper::getAssetUrl()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 12
ccs 0
cts 10
cp 0
crap 12
rs 9.4285
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