AdapterFactory::get()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 22
c 1
b 0
f 0
rs 9.2
cc 3
eloc 14
nc 3
nop 2
1
<?php
2
3
/*
4
 * This file is part of HeriJobQueueBundle.
5
 *
6
 * (c) Alexandre Mogère
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Heri\Bundle\JobQueueBundle\DependencyInjection\Factory;
13
14
use Heri\Bundle\JobQueueBundle\Adapter as Adapter;
15
use Heri\Bundle\JobQueueBundle\Exception\InvalidAdapterDefinitionException;
16
17
/**
18
 * Adapter factory.
19
 */
20
class AdapterFactory
21
{
22
    public static $em;
23
24
    /**
25
     * Create staticly desired Adapter.
26
     *
27
     * @param string $type   Type of Adapter to create
28
     * @param array  $config Configuration container
29
     *
30
     * @return AdapterInterface Adapter instance
31
     */
32
    public static function get($type, $config)
33
    {
34
        $instance = null;
0 ignored issues
show
Unused Code introduced by
$instance 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...
35
        $options = [];
36
37
        switch ($type) {
38
39
            case 'doctrine':
40
                $instance = new Adapter\DoctrineAdapter($options);
41
                $instance->em = self::$em;
42
                break;
43
44
            case 'amqp':
45
                $instance = new Adapter\AmqpAdapter($config['amqp_connection']);
46
                break;
47
48
            default:
49
                throw new InvalidAdapterDefinitionException();
50
        }
51
52
        return $instance;
53
    }
54
}
55