Passed
Push — master ( e1ac4a...a9f297 )
by
unknown
09:26 queued 11s
created

azureEndpoint()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
use Illuminate\Support\Facades\Storage;
4
5
if (!function_exists('s3Endpoint')) {
6
    /**
7
     * @param string $disk
8
     * @return string
9
     */
10
    function s3Endpoint($disk = 'libraries')
11
    {
12
        $scheme = config("filesystems.disks.{$disk}.use_https") ? 'https://' : '';
13
        return $scheme . config("filesystems.disks.{$disk}.bucket") . '.' . Storage::disk($disk)->getAdapter()->getClient()->getEndpoint()->getHost();
0 ignored issues
show
Bug introduced by
The method getAdapter() does not exist on Illuminate\Contracts\Filesystem\Filesystem. It seems like you code against a sub-type of said class. However, the method does not exist in Illuminate\Contracts\Filesystem\Cloud. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

13
        return $scheme . config("filesystems.disks.{$disk}.bucket") . '.' . Storage::disk($disk)->/** @scrutinizer ignore-call */ getAdapter()->getClient()->getEndpoint()->getHost();
Loading history...
14
    }
15
}
16
17
if (!function_exists('azureEndpoint')) {
18
    /**
19
     * @param string $disk
20
     * @return string
21
     */
22
    function azureEndpoint($disk = 'libraries')
23
    {
24
        $scheme = config("filesystems.disks.{$disk}.use_https") ? 'https://' : '';
25
        return $scheme . env('AZURE_ACCOUNT_NAME') . '.blob.' . env('AZURE_ENDPOINT_SUFFIX') . '/' . env('AZURE_CONTAINER');
26
    }
27
}
28
29
30
if (!function_exists('bytesToHuman')) {
31
    /**
32
     * @param float $bytes
33
     * @return string
34
     */
35
    function bytesToHuman($bytes)
36
    {
37
        $units = ['B', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb'];
38
39
        for ($i = 0; $bytes > 1024; $i++) {
40
            $bytes /= 1024;
41
        }
42
43
        return round($bytes, 2) . ' ' . $units[$i];
44
    }
45
}
46
47
if (!function_exists('replaceAccents')) {
48
    /**
49
     * @param string $str
50
     * @return bool|string
51
     */
52
    function replaceAccents($str)
53
    {
54
        return iconv('UTF-8', 'ASCII//TRANSLIT', $str);
55
    }
56
}
57
58
if (!function_exists('sanitizeFilename')) {
59
    /**
60
     * @param string $filename
61
     * @return string
62
     */
63
    function sanitizeFilename($filename)
64
    {
65
        $sanitizedFilename = replaceAccents($filename);
66
67
        $invalid = array(
68
            ' ' => '-',
69
            '%20' => '-',
70
            '_' => '-',
71
        );
72
73
        $sanitizedFilename = str_replace(array_keys($invalid), array_values($invalid), $sanitizedFilename);
74
75
        $sanitizedFilename = preg_replace('/[^A-Za-z0-9-\. ]/', '', $sanitizedFilename); // Remove all non-alphanumeric except .
76
        $sanitizedFilename = preg_replace('/\.(?=.*\.)/', '', $sanitizedFilename); // Remove all but last .
77
        $sanitizedFilename = preg_replace('/-+/', '-', $sanitizedFilename); // Replace any more than one - in a row
78
        $sanitizedFilename = str_replace('-.', '.', $sanitizedFilename); // Remove last - if at the end
79
        $sanitizedFilename = strtolower($sanitizedFilename); // Lowercase
80
81
        return $sanitizedFilename;
82
    }
83
}
84