These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\MediaBundle\Helper\Imagine; |
||
4 | |||
5 | use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration; |
||
6 | use Symfony\Component\Filesystem\Filesystem; |
||
7 | use Symfony\Component\Routing\RequestContext; |
||
8 | |||
9 | class WebPathResolver extends \Liip\ImagineBundle\Imagine\Cache\Resolver\WebPathResolver |
||
10 | { |
||
11 | /** |
||
12 | * @var FilterConfiguration |
||
13 | */ |
||
14 | protected $filterConfig; |
||
15 | |||
16 | /** |
||
17 | * @param Filesystem $filesystem |
||
18 | * @param RequestContext $requestContext |
||
19 | * @param string $webRootDir |
||
20 | * @param string $cachePrefix |
||
21 | * @param FilterConfiguration $filterConfig |
||
22 | */ |
||
23 | public function __construct(Filesystem $filesystem, RequestContext $requestContext, $webRootDir, $cachePrefix = 'media/cache', FilterConfiguration $filterConfig) |
||
24 | { |
||
25 | parent::__construct($filesystem, $requestContext, $webRootDir, $cachePrefix); |
||
26 | |||
27 | $this->filterConfig = $filterConfig; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * {@inheritdoc} |
||
32 | */ |
||
33 | protected function getFileUrl($path, $filter) |
||
34 | { |
||
35 | $filterConf = $this->filterConfig->get($filter); |
||
36 | $path = $this->changeFileExtension($path, $filterConf['format']); |
||
37 | |||
38 | return parent::getFileUrl($path, $filter); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | public function resolve($path, $filter) |
||
45 | { |
||
46 | return sprintf('%s/%s', |
||
47 | $this->getBaseUrl(), |
||
48 | $this->getFileUrl($path, $filter) |
||
49 | ); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param string $path |
||
54 | * @param string $format |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | View Code Duplication | private function changeFileExtension($path, $format) |
|
0 ignored issues
–
show
|
|||
59 | { |
||
60 | if (!$format) { |
||
61 | return $path; |
||
62 | } |
||
63 | |||
64 | $info = pathinfo($path); |
||
65 | $path = $info['dirname'] . DIRECTORY_SEPARATOR . $info['filename'] . '.' . $format; |
||
66 | |||
67 | return $path; |
||
68 | } |
||
69 | } |
||
70 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.