ResizeCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
c 2
b 0
f 0
dl 0
loc 40
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A execute() 0 25 5
1
<?php
2
3
namespace Jackal\ImageMerge\Command;
4
5
use Jackal\ImageMerge\Command\Options\DimensionCommandOption;
6
use Jackal\ImageMerge\Model\Image;
7
use Jackal\ImageMerge\ValueObject\Dimention;
8
9
class ResizeCommand extends AbstractCommand
10
{
11
    /**
12
     * ResizeCommand constructor.
13
     * @param DimensionCommandOption $options
14
     */
15
    public function __construct(DimensionCommandOption $options)
16
    {
17
        parent::__construct($options);
18
    }
19
20
    /**
21
     * @param Image $image
22
     * @return Image
23
     */
24
    public function execute(Image $image)
25
    {
26
        if (!$this->options->getDimention()->getWidth()) {
0 ignored issues
show
Bug introduced by
The method getDimention() does not exist on Jackal\ImageMerge\Comman...\CommandOptionInterface. It seems like you code against a sub-type of Jackal\ImageMerge\Comman...\CommandOptionInterface such as Jackal\ImageMerge\Comman...\DimensionCommandOption. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        if (!$this->options->/** @scrutinizer ignore-call */ getDimention()->getWidth()) {
Loading history...
27
            $this->options->add('dimention', new Dimention(round($image->getAspectRatio() * $this->options->getDimention()->getHeight()), $this->options->getDimention()->getHeight()));
0 ignored issues
show
Bug introduced by
The method add() does not exist on Jackal\ImageMerge\Comman...\CommandOptionInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Jackal\ImageMerge\Comman...\CommandOptionInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
            $this->options->/** @scrutinizer ignore-call */ 
28
                            add('dimention', new Dimention(round($image->getAspectRatio() * $this->options->getDimention()->getHeight()), $this->options->getDimention()->getHeight()));
Loading history...
28
        }
29
30
        if (!$this->options->getDimention()->getHeight()) {
31
            $this->options->add('dimention', new Dimention($this->options->getDimention()->getWidth(), round($this->options->getDimention()->getWidth() / $image->getAspectRatio())));
32
        }
33
34
        $width = $this->options->getDimention()->getWidth();
35
        $height = $this->options->getDimention()->getHeight();
36
37
        if ($image->getWidth() != $width or $image->getHeight() != $height) {
38
            $resourceResized = imagecreatetruecolor($width, $height);
39
            imagealphablending($resourceResized, false);
0 ignored issues
show
Bug introduced by
It seems like $resourceResized can also be of type false; however, parameter $image of imagealphablending() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
            imagealphablending(/** @scrutinizer ignore-type */ $resourceResized, false);
Loading history...
40
            imagesavealpha($resourceResized, true);
0 ignored issues
show
Bug introduced by
It seems like $resourceResized can also be of type false; however, parameter $image of imagesavealpha() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
            imagesavealpha(/** @scrutinizer ignore-type */ $resourceResized, true);
Loading history...
41
            $transparent = imagecolorallocatealpha($resourceResized, 255, 255, 255, 127);
0 ignored issues
show
Bug introduced by
It seems like $resourceResized can also be of type false; however, parameter $image of imagecolorallocatealpha() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
            $transparent = imagecolorallocatealpha(/** @scrutinizer ignore-type */ $resourceResized, 255, 255, 255, 127);
Loading history...
42
            imagecolortransparent($resourceResized, $transparent);
0 ignored issues
show
Bug introduced by
It seems like $resourceResized can also be of type false; however, parameter $image of imagecolortransparent() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

42
            imagecolortransparent(/** @scrutinizer ignore-type */ $resourceResized, $transparent);
Loading history...
43
            imagecopyresampled($resourceResized, $image->getResource(), 0, 0, 0, 0, $width, $height, $image->getWidth(), $image->getHeight());
0 ignored issues
show
Bug introduced by
It seems like $resourceResized can also be of type false; however, parameter $dst_image of imagecopyresampled() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
            imagecopyresampled(/** @scrutinizer ignore-type */ $resourceResized, $image->getResource(), 0, 0, 0, 0, $width, $height, $image->getWidth(), $image->getHeight());
Loading history...
44
45
            return $image->assignResource($resourceResized);
46
        }
47
48
        return $image;
49
    }
50
}
51