Completed
Pull Request — master (#21)
by
unknown
02:08
created

PasswordGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 20
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 15 3
1
<?php
2
3
namespace Knp\Rad\User\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;
8
9
class PasswordGenerator implements CompilerPassInterface
10
{
11
    const GENERATOR_INDEX = 0;
12
13
    public function process(ContainerBuilder $container)
14
    {
15
        if ( ! extension_loaded('openssl')) {
16
            return;
17
        }
18
19
        $listener = $container->findDefinition('knp_rad_user.event_listener.persistence.password_generation_listener');
20
21
        try {
22
            $generator = $listener->getArgument(self::GENERATOR_INDEX);
0 ignored issues
show
Unused Code introduced by
$generator is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
23
        } catch (OutOfBoundsException $e) {
24
            $sslGenerator = $container->findDefinition('knp_rad_user.password.generator.pseudo_random_bytes_generator');
25
            $listener->setArguments([$sslGenerator]);
26
        }
27
    }
28
}
29