Test Setup Failed
Push — 0.9 ( dd36a2 )
by Ben
05:07
created

AssetHelper::isImage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Thinktomorrow\AssetLibrary;
4
5
use Illuminate\Support\Str;
6
7
class AssetHelper
8
{
9
    public static function isImage(string $mimeType): bool
10
    {
11
        return Str::endsWith($mimeType, [
12
            'png', 'jpg', 'jpeg', 'gif', 'svg', 'webp'
13
        ]);
14
    }
15
16
    public static function getExtension(string $path): string
17
    {
18
        return pathinfo($path, PATHINFO_EXTENSION);
0 ignored issues
show
Bug Best Practice introduced by
The expression return pathinfo($path, T...ary\PATHINFO_EXTENSION) could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
19
    }
20
21
    public static function getHumanReadableSize(int $sizeInBytes): string
22
    {
23
        [$size, $unit] = explode(' ',  \Spatie\MediaLibrary\Support\File::getHumanReadableSize($sizeInBytes));
24
25
        return round($size) . ' ' . $unit;
0 ignored issues
show
Bug introduced by
$size of type string is incompatible with the type double|integer expected by parameter $num of round(). ( Ignorable by Annotation )

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

25
        return round(/** @scrutinizer ignore-type */ $size) . ' ' . $unit;
Loading history...
26
    }
27
28
    public static function getBaseName(string $path): string
29
    {
30
        return basename($path, '.'.static::getExtension($path));
31
    }
32
}
33