Completed
Pull Request — master (#268)
by
unknown
01:14
created

Xhgui_Storage_Factory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A factory() 0 14 4
A create() 0 4 1
1
<?php
2
3
/**
4
 * Factory for storage classes
5
 */
6
class Xhgui_Storage_Factory
7
{
8
    /**
9
     * @param $config
10
     * @return Xhgui_Storage_File|Xhgui_Storage_Mongo|Xhgui_Storage_PDO
11
     * @throws MongoConnectionException
12
     * @throws MongoException
13
     */
14
    public static function factory($config)
15
    {
16
        switch ($config['save.handler']) {
17
            case 'pdo':
18
                return new \Xhgui_Storage_PDO($config);
19
20
            case 'mongodb':
21
                return new \Xhgui_Storage_Mongo($config);
22
23
            default:
24
            case 'file':
0 ignored issues
show
Unused Code introduced by
case 'file': return ..._Storage_File($config); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
25
                return new \Xhgui_Storage_File($config);
26
        }
27
    }
28
29
    /**
30
     * For usage with factory instance - for example for easier testing
31
     *
32
     * @param $config
33
     * @return Xhgui_Storage_File|Xhgui_Storage_Mongo|Xhgui_Storage_PDO
34
     * @throws MongoConnectionException
35
     * @throws MongoException
36
     */
37
    public function create($config)
38
    {
39
        return self::factory($config);
40
    }
41
}
42