ImageAssetCommand::getResourceToApply()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Jackal\ImageMerge\Command\Asset;
4
5
use Exception;
6
use Jackal\ImageMerge\Command\AbstractCommand;
7
use Jackal\ImageMerge\Command\Options\SingleCoordinateFileObjectCommandOption;
8
use Jackal\ImageMerge\Model\Format\ImageReader;
9
use Jackal\ImageMerge\Model\Image;
10
11
/**
12
 * Class ImageAsset
13
 * @package Jackal\ImageMerge\Model\Asset
14
 */
15
class ImageAssetCommand extends AbstractCommand
16
{
17
    /**
18
     * ImageAssetCommand constructor.
19
     * @param SingleCoordinateFileObjectCommandOption $options
20
     */
21
    public function __construct(SingleCoordinateFileObjectCommandOption $options)
22
    {
23
        parent::__construct($options);
24
    }
25
26
    /**
27
     * @return resource
28
     * @throws Exception
29
     */
30
    protected function getResourceToApply()
31
    {
32
        $res = ImageReader::fromPathname($this->options->getFile());
0 ignored issues
show
Bug introduced by
The method getFile() 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...FileObjectCommandOption. ( Ignorable by Annotation )

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

32
        $res = ImageReader::fromPathname($this->options->/** @scrutinizer ignore-call */ getFile());
Loading history...
33
34
        return $res->getResource();
35
    }
36
37
    /**
38
     * @return int
39
     * @throws Exception
40
     */
41
    protected function getWidth()
42
    {
43
        return imagesx($this->getResourceToApply());
44
    }
45
46
    /**
47
     * @return int
48
     * @throws Exception
49
     */
50
    protected function getHeight()
51
    {
52
        return imagesy($this->getResourceToApply());
53
    }
54
55
    /**
56
     * @param Image $image
57
     * @return Image
58
     * @throws Exception
59
     */
60
    public function execute(Image $image)
61
    {
62
        /** @var SingleCoordinateFileObjectCommandOption $options */
63
        $options = $this->options;
64
        imagecolortransparent($image->getResource());
65
        imagecopyresampled($image->getResource(), $this->getResourceToApply(), $options->getCoordinate1()->getX(), $options->getCoordinate1()->getY(), 0, 0, $this->getWidth(), $this->getHeight(), $this->getWidth(), $this->getHeight());
66
        $image->assignResource($image->getResource());
67
68
        return $image;
69
    }
70
}
71