CropOuter::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
cc 2
eloc 14
c 3
b 0
f 2
nc 2
nop 1
dl 0
loc 22
rs 9.7998
1
<?php
2
3
namespace Jackal\ImageMerge\Command\Effect;
4
5
use Jackal\ImageMerge\Builder\ImageBuilder;
6
use Jackal\ImageMerge\Command\AbstractCommand;
7
use Jackal\ImageMerge\Command\Options\DimensionCommandOption;
8
use Jackal\ImageMerge\Model\Image;
9
10
class CropOuter extends AbstractCommand
11
{
12
    /**
13
     * CropOuter constructor.
14
     * @param DimensionCommandOption $options
15
     */
16
    public function __construct(DimensionCommandOption $options)
17
    {
18
        parent::__construct($options);
19
    }
20
21
    /**
22
     * @param Image $image
23
     * @return Image
24
     */
25
    public function execute(Image $image)
26
    {
27
        $newWidth = $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

27
        $newWidth = $this->options->/** @scrutinizer ignore-call */ getDimention()->getWidth();
Loading history...
28
        $newHeight = $this->options->getDimention()->getHeight();
29
30
        $thumbAspect = $newWidth / $newHeight;
31
        $builder = new ImageBuilder($image);
32
        if ($image->getAspectRatio() >= $thumbAspect) {
33
            $builder->resize($newWidth, null);
34
        } else {
35
            $builder->resize(null, $newHeight);
36
        }
37
38
        $posX = ($newWidth - $image->getWidth()) / 2;
39
        $posY = ($newHeight - $image->getHeight()) / 2;
40
41
        $image_p = imagecreatetruecolor($newWidth, $newHeight);
42
        imagecopyresampled($image_p, $image->getResource(), $posX, $posY, 0, 0, $image->getWidth(), $image->getHeight(), $image->getWidth(), $image->getHeight());
0 ignored issues
show
Bug introduced by
It seems like $image_p 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

42
        imagecopyresampled(/** @scrutinizer ignore-type */ $image_p, $image->getResource(), $posX, $posY, 0, 0, $image->getWidth(), $image->getHeight(), $image->getWidth(), $image->getHeight());
Loading history...
43
44
        $image->assignResource($image_p);
45
46
        return $image;
47
    }
48
}
49