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

BaseGenerator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 44
rs 10
c 0
b 0
f 0

7 Methods

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