Completed
Push — 1.3 ( 698fb2...398444 )
by Kamil
122:51 queued 98:34
created

ImageExistenceChecker   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A doesImageWithUrlExist() 0 8 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Behat\Service\Checker;
15
16
use Liip\ImagineBundle\Service\FilterService;
17
18
final class ImageExistenceChecker implements ImageExistenceCheckerInterface
19
{
20
    /** @var FilterService */
21
    private $filterService;
22
23
    /** @var string */
24
    private $mediaRootPath;
25
26
    public function __construct(FilterService $filterService, string $mediaRootPath)
27
    {
28
        $this->filterService = $filterService;
29
        $this->mediaRootPath = $mediaRootPath;
30
    }
31
32
    public function doesImageWithUrlExist(string $imageUrl, string $liipImagineFilter): bool
33
    {
34
        $imageUrl = str_replace($liipImagineFilter . '/', '', substr($imageUrl, strpos($imageUrl, $liipImagineFilter), strlen($imageUrl)));
35
36
        $browserImagePath = $this->filterService->getUrlOfFilteredImage($imageUrl, $liipImagineFilter);
37
38
        return file_exists($this->mediaRootPath . parse_url($browserImagePath, PHP_URL_PATH));
39
    }
40
}
41