Completed
Push — master ( 663845...79fb76 )
by Igor
18s queued 13s
created

ImageViewFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 30
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A create() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusLagersystemPlugin\Factory\Image;
6
7
use Liip\ImagineBundle\Service\FilterService;
8
use Setono\SyliusLagersystemPlugin\View\Image\ImageView;
9
use Sylius\Component\Core\Model\ImageInterface;
10
11
class ImageViewFactory implements ImageViewFactoryInterface
12
{
13
    /** @var string */
14
    protected $imageViewClass;
15
16
    /** @var FilterService */
17
    protected $filterService;
18
19
    /** @var string */
20
    protected $filter;
21
22
    public function __construct(
23
        string $imageViewClass,
24
        FilterService $filterService,
25
        string $filter
26
    ) {
27
        $this->imageViewClass = $imageViewClass;
28
        $this->filterService = $filterService;
29
        $this->filter = $filter;
30
    }
31
32
    public function create(ImageInterface $image): ImageView
33
    {
34
        /** @var ImageView $imageView */
35
        $imageView = new $this->imageViewClass();
36
        $imageView->type = $image->getType();
37
        $imageView->path = $image->getPath();
38
        $imageView->cachedPath = $this->filterService->getUrlOfFilteredImage($image->getPath(), $this->filter);
39
40
        return $imageView;
41
    }
42
}
43