Completed
Push — master ( 598fcc...9a7d0c )
by Mark
01:20
created

Xhgui_Saver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B factory() 0 25 5
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    /**
11
     * Get a saver instance based on configuration data.
12
     *
13
     * @param array $config The configuration data.
14
     * @return Xhgui_Saver_File|Xhgui_Saver_Mongo|Xhgui_Saver_Upload
15
     */
16
    public static function factory($config)
17
    {
18
        switch ($config['save.handler']) {
19
20
            case 'file':
21
                return new Xhgui_Saver_File($config['save.handler.filename']);
22
23
            case 'upload':
24
                $timeout = 3;
25
                if (isset($config['save.handler.upload.timeout'])) {
26
                    $timeout = $config['save.handler.upload.timeout'];
27
                }
28
                return new Xhgui_Saver_Upload(
29
                    $config['save.handler.upload.uri'],
30
                    $timeout
31
                );
32
33
            case 'mongodb':
34
            default:
35
                $mongo = new MongoClient($config['db.host'], $config['db.options']);
36
                $collection = $mongo->{$config['db.db']}->results;
37
                $collection->findOne();
38
                return new Xhgui_Saver_Mongo($collection);
39
        }
40
    }
41
}
42