BaseGenerator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 40
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
requirementsAreInstalled() 0 1 ?
supportedExtensions() 0 1 ?
supportedMimetypes() 0 1 ?
A canConvert() 0 16 4
A canHandleMime() 0 4 1
A canHandleExtension() 0 4 1
A getType() 0 4 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