Completed
Pull Request — master (#898)
by
unknown
01:43
created

BaseGenerator::getParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Spatie\MediaLibrary\ImageGenerators;
4
5
use Spatie\MediaLibrary\Media;
6
use Illuminate\Support\Collection;
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
    public function getParams(): Collection
43
    {
44
        return collect();
45
    }
46
47
    abstract public function requirementsAreInstalled(): bool;
48
49
    abstract public function supportedExtensions(): Collection;
50
51
    abstract public function supportedMimetypes(): Collection;
52
}
53