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

ImageExistenceChecker::doesImageWithUrlExist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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