Xhgui_Saver   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 43
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B factory() 0 34 6
1
<?php
2
/**
3
 * A small factory to handle creation of the profile saver instance.
4
 *
5
 * This class only exists to handle cases where an incompatible version of pimple
6
 * exists in the host application.
7
 */
8
class Xhgui_Saver
9
{
10
    /**
11
     * Get a saver instance based on configuration data.
12
     *
13
     * @param array $config The configuration data.
14
     * @return Xhgui_Saver_Interface
15
     */
16
    public static function factory($config)
17
    {
18
        switch ($config['save.handler']) {
19
            case 'file':
20
                return new Xhgui_Saver_File($config['save.handler.filename']);
21
22
            case 'upload':
23
                $timeout = 3;
24
                if (isset($config['save.handler.upload.timeout'])) {
25
                    $timeout = $config['save.handler.upload.timeout'];
26
                }
27
                return new Xhgui_Saver_Upload(
28
                    $config['save.handler.upload.uri'],
29
                    $timeout
30
                );
31
32
            case 'pdo':
33
                return new Xhgui_Saver_Pdo(
34
                    new PDO(
35
                        $config['pdo']['dsn'],
36
                        $config['pdo']['user'],
37
                        $config['pdo']['pass']
38
                    ),
39
                    $config['pdo']['table']
40
                );
41
42
            case 'mongodb':
43
            default:
44
                $mongo = new MongoClient($config['db.host'], $config['db.options'], $config['db.driverOptions']);
45
                $collection = $mongo->{$config['db.db']}->results;
46
                $collection->findOne();
47
                return new Xhgui_Saver_Mongo($collection);
48
        }
49
    }
50
}
51