BaseGenerator::requirementsAreInstalled()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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