Completed
Pull Request — symfony5 (#1256)
by
unknown
09:52
created

NonFunctionalFilterExceptionPass   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 20 6
1
<?php
2
3
namespace Liip\ImagineBundle\DependencyInjection\Compiler;
4
5
use Liip\ImagineBundle\Imagine\Filter\Loader\NonFunctionalPasteFilterLoader;
6
use Liip\ImagineBundle\Imagine\Filter\Loader\NonFunctionalWatermarkFilterLoader;
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
10
/**
11
 * For transitioning from Symfony 4 to Symfony 5 with the removal
12
 * of the kernel.root_dir parameter.
13
 */
14
class NonFunctionalFilterExceptionPass implements CompilerPassInterface
15
{
16
    public function process(ContainerBuilder $container)
17
    {
18
        // only needed if kernel.root_dir is no longer present
19
        if ($container->hasParameter('kernel.root_dir')) {
20
            return;
21
        }
22
23
        $filterSets = $container->getParameter('liip_imagine.filter_sets');
24
        foreach ($filterSets as $filterSet) {
25
            foreach ($filterSet['filters'] as $filterName => $filter) {
26
                if ($filter === 'paste') {
27
                    throw new \InvalidArgumentException(sprintf('The "paste" filter no longer works in Symfony 5.0. Please use "paste_image" and adapt the "image" to be relative to the "%kernel.project_dir%" instead of "%kernel.root_dir%".'));
28
                }
29
30
                if ($filter === 'watermark') {
31
                    throw new \InvalidArgumentException(sprintf('The "paste" filter no longer works in Symfony 5.0. Please use "paste_image" and adapt the "image" to be relative to the "%kernel.project_dir%" instead of "%kernel.root_dir%".'));
32
                }
33
            }
34
        }
35
    }
36
}