Completed
Push — develop ( 64a224...17d645 )
by Florent
03:11
created

CheckerCompilerPass   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 46.15 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 6
c 2
b 1
f 1
lcom 0
cbo 4
dl 12
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 12 23 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace SpomkyLabs\JoseBundle\DependencyInjection\Compiler;
13
14
use Assert\Assertion;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Reference;
18
19
final class CheckerCompilerPass implements CompilerPassInterface
20
{
21
    public function process(ContainerBuilder $container)
22
    {
23
        if (!$container->hasDefinition('jose.checker_manager')) {
24
            return;
25
        }
26
27
        $definition = $container->getDefinition('jose.checker_manager');
28
29
        $taggedClaimCheckerServices = $container->findTaggedServiceIds('jose.checker.claim');
30
        $taggedHeaderCheckerServices = $container->findTaggedServiceIds('jose.checker.header');
31 View Code Duplication
        foreach ($taggedClaimCheckerServices as $id => $tags) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
32
            foreach ($tags as $attributes) {
33
                Assertion::keyExists($attributes, 'alias', sprintf("The claim checker '%s' does not have any 'alias' attribute.", $id));
34
                $definition->addMethodCall('addClaimChecker', [new Reference($id), $attributes['alias']]);
35
            }
36
        }
37 View Code Duplication
        foreach ($taggedHeaderCheckerServices as $id => $tags) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
38
            foreach ($tags as $attributes) {
39
                Assertion::keyExists($attributes, 'alias', sprintf("The header checker '%s' does not have any 'alias' attribute.", $id));
40
                $definition->addMethodCall('addHeaderChecker', [new Reference($id), $attributes['alias']]);
41
            }
42
        }
43
    }
44
}
45