Completed
Push — master ( 8c862e...56eee6 )
by Freek
02:32
created

BaseGenerator::canHandleMime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Spatie\MediaLibrary\ImageGenerators;
4
5
use Illuminate\Support\Collection;
6
use Spatie\MediaLibrary\Helpers\File;
7
8
abstract class BaseGenerator implements ImageGenerator
9
{
10
    public function canConvert(string $path): bool
11
    {
12
        if (! file_exists($path)) {
13
            return false;
14
        }
15
16
        if (! $this->requirementsAreInstalled()) {
17
            return false;
18
        }
19
20
        if ($this->supportedExtensions()->contains(pathinfo($path, PATHINFO_EXTENSION))) {
21
            return true;
22
        }
23
24
        if ($this->supportedMimetypes()->contains(File::getMimetype($path))) {
25
            return true;
26
        }
27
28
        return false;
29
    }
30
31
    public function canHandleMime(string $mime = ''): bool
32
    {
33
        return $this->supportedMimetypes()->contains($mime);
34
    }
35
36
    public function canHandleExtension(string $extension = ''): bool
37
    {
38
        return $this->supportedExtensions()->contains($extension);
39
    }
40
41
    public function getType(): string
42
    {
43
        return strtolower(class_basename(static::class));
44
    }
45
46
    abstract public function requirementsAreInstalled(): bool;
47
48
    abstract public function supportedExtensions(): Collection;
49
50
    abstract public function supportedMimetypes(): Collection;
51
}
52