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

Xhgui_Saver::factory()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.439
c 0
b 0
f 0
cc 5
eloc 17
nc 5
nop 1
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