AbstractManipulator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 65
ccs 8
cts 14
cp 0.5714
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A performConversions() 0 13 3
A canConvert() 0 15 3
1
<?php
2
3
namespace ByTIC\MediaLibrary\Media\Manipulators;
4
5
use ByTIC\MediaLibrary\Conversions\Conversion;
6
use ByTIC\MediaLibrary\Conversions\ConversionCollection;
7
use ByTIC\MediaLibrary\Media\Media;
8
use Nip\Collection;
9
10
/**
11
 * Class AbstractManipulator.
12
 */
13
abstract class AbstractManipulator implements ManipulatorInterface
14
{
15
    /**
16
     * @param Media $media
17
     *
18
     * @return bool
19
     */
20 4
    public function canConvert(Media $media): bool
21
    {
22 4
        if (!$this->requirementsAreInstalled()) {
23
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the return type mandated by ByTIC\MediaLibrary\Media...Interface::canConvert() of true.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
24
        }
25
26 4
        if (!$this->supportedExtensions()->contains(strtolower($media->getExtension()))) {
27 1
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the return type mandated by ByTIC\MediaLibrary\Media...Interface::canConvert() of true.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
28
        }
29
//        $urlGenerator = UrlGeneratorFactory::createForMedia($media);
30
//        if (method_exists($urlGenerator, 'getPath') && file_exists($media->getPath())
31
//            && $this->supportedMimetypes()->contains(strtolower(File::getMimetype($media->getPath())))) {
32
//            return true;
33
//        }
34 3
        return true;
35
    }
36
37
    /**
38
     * @param ConversionCollection $conversions
39
     * @param Media                $media
40
     *
41
     * @return int Number of convertions performed
42
     */
43 3
    public function performConversions(ConversionCollection $conversions, Media $media)
44
    {
45 3
        if ($conversions->isEmpty()) {
46 3
            return;
47
        }
48
49
        $i = 0;
50
        foreach ($conversions as $conversion) {
51
            $this->performConversion($media, $conversion);
52
            $i++;
53
        }
54
55
        return $i;
56
    }
57
58
    /**
59
     * @param Media      $media
60
     * @param Conversion $conversion
61
     */
62
    abstract public function performConversion(Media $media, Conversion $conversion);
63
64
    /**
65
     * @return bool
66
     */
67
    abstract public function requirementsAreInstalled(): bool;
68
69
    /**
70
     * @return Collection
71
     */
72
    abstract public function supportedExtensions(): Collection;
73
74
    /**
75
     * @return Collection
76
     */
77
    abstract public function supportedMimetypes(): Collection;
78
}
79