Completed
Pull Request — master (#21)
by
unknown
03:33 queued 01:31
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\Definition;
8
use Symfony\Component\DependencyInjection\Reference;
9
use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;
10
11
class PasswordGenerator implements CompilerPassInterface
12
{
13
    const GENERATOR_INDEX = 0;
14
15
    public function process(ContainerBuilder $container)
16
    {
17
        if (!extension_loaded('openssl')) {
18
            return;
19
        }
20
21
        $listener = $container->findDefinition('knp_rad_user.event_listener.persistence.password_generation_listener');
22
23
        try {
24
            $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...
25
        } catch (OutOfBoundsException $e) {
26
            $sslGenerator = $container->findDefinition('knp_rad_user.password.generator.pseudo_random_bytes_generator');
27
            $listener->setArguments([$sslGenerator]);
28
        }
29
    }
30
}
31