Completed
Push — ezp-30696 ( 9bb3ad...3bd812 )
by
unknown
49:02 queued 18:35
created

FieldRegistryPass::process()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 27

Duplication

Lines 27
Ratio 100 %

Importance

Changes 0
Metric Value
cc 5
nc 5
nop 1
dl 27
loc 27
rs 9.1768
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the FieldRegistryPass class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Base\Container\Compiler\Search;
10
11
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13
use Symfony\Component\DependencyInjection\Reference;
14
use LogicException;
15
16
/**
17
 * This compiler pass will register eZ Publish indexable field types.
18
 */
19 View Code Duplication
class FieldRegistryPass implements CompilerPassInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
20
{
21
    /**
22
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
23
     *
24
     * @throws \LogicException
25
     */
26
    public function process(ContainerBuilder $container)
27
    {
28
        if (!$container->hasDefinition('ezpublish.search.common.field_registry')) {
29
            return;
30
        }
31
32
        $fieldRegistryDefinition = $container->getDefinition('ezpublish.search.common.field_registry');
33
34
        foreach ($container->findTaggedServiceIds('ezpublish.fieldType.indexable') as $id => $attributes) {
35
            foreach ($attributes as $attribute) {
36
                if (!isset($attribute['alias'])) {
37
                    throw new LogicException(
38
                        'ezpublish.fieldType.indexable service tag needs an "alias" attribute to ' .
39
                        'identify the indexable field type. None given.'
40
                    );
41
                }
42
43
                $fieldRegistryDefinition->addMethodCall(
44
                    'registerType',
45
                    [
46
                        $attribute['alias'],
47
                        new Reference($id),
48
                    ]
49
                );
50
            }
51
        }
52
    }
53
}
54