Completed
Pull Request — symfony5 (#1255)
by Axel
01:35
created

PasteFilterLoader::load()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 9.9666
cc 3
nc 4
nop 2
1
<?php
2
3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\Imagine\Filter\Loader;
13
14
use Imagine\Image\ImageInterface;
15
use Imagine\Image\ImagineInterface;
16
use Imagine\Image\Point;
17
18
class PasteFilterLoader implements LoaderInterface
19
{
20
    /**
21
     * @var ImagineInterface
22
     */
23
    protected $imagine;
24
25
    /**
26
     * @var string
27
     */
28
    protected $projectDir;
29
30
    public function __construct(ImagineInterface $imagine, $projectDir)
31
    {
32
        $this->imagine = $imagine;
33
        $this->projectDir = $projectDir;
34
    }
35
36
    /**
37
     * @see \Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface::load()
38
     *
39
     * @param ImageInterface $image
40
     * @param array          $options
41
     *
42
     * @return ImageInterface|static
43
     */
44
    public function load(ImageInterface $image, array $options = [])
45
    {
46
        $x = isset($options['start'][0]) ? $options['start'][0] : null;
47
        $y = isset($options['start'][1]) ? $options['start'][1] : null;
48
49
        $file = $this->projectDir . '/' . $options['image'];
50
51
        if (!file_exists($file) {
52
            @trigger_error(
53
                'The ' . $file . ' does not exists, change the path based on kernel.project_dir parameter',
54
                E_USER_DEPRECATED
55
            );
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected ';'
Loading history...
56
            $file = $this->projectDir . '/app/' . $options['image'];
57
        }
58
59
        $destImage = $this->imagine->open($file);
60
61
        return $image->paste($destImage, new Point($x, $y));
62
    }
63
}
64