GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Connections::createConnection()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 18
rs 9.9
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
/**
3
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Database;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Spl\Patterns\Structural\Provider\AbstractProvider;
19
use O2System\Spl\Patterns\Structural\Provider\ValidationInterface;
20
21
/**
22
 * Class Connections
23
 *
24
 * @package O2System\Database
25
 */
26
class Connections extends AbstractProvider implements ValidationInterface
27
{
28
    /**
29
     * Connections::$config
30
     *
31
     * @var DataStructures\Config
32
     */
33
    private $config;
34
35
    /**
36
     * Connections::__construct
37
     *
38
     * @param DataStructures\Config $config
39
     *
40
     * @return Connections
41
     */
42
    public function __construct(DataStructures\Config $config)
43
    {
44
        $this->config = $config;
45
    }
46
47
    // ------------------------------------------------------------------------
48
49
    public function &loadConnection($connectionOffset)
50
    {
51
        $loadConnection[ $connectionOffset ] = false;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$loadConnection was never initialized. Although not strictly required by PHP, it is generally a good practice to add $loadConnection = array(); before regardless.
Loading history...
52
53
        if ( ! $this->exists($connectionOffset) and $this->config->offsetExists($connectionOffset)) {
54
55
            $connectionConfig = $this->config->offsetGet($connectionOffset);
56
57
            if (is_array($connectionConfig)) {
58
                new DataStructures\Config($this->config[ $connectionOffset ]);
59
            }
60
61
            $this->createConnection($connectionOffset, $connectionConfig);
62
63
            return $this->getObject($connectionOffset);
64
65
        } elseif ($this->exists($connectionOffset)) {
66
            return $this->getObject($connectionOffset);
67
        }
68
69
        return $loadConnection;
70
    }
71
72
    // ------------------------------------------------------------------------
73
74
    /**
75
     * Connections::createConnection
76
     *
77
     * Create Item Pool
78
     *
79
     * @param string                $connectionOffset
80
     * @param DataStructures\Config $connectionConfig
81
     *
82
     * @return bool|\O2System\Database\Sql\Abstracts\AbstractConnection|\O2System\Database\NoSql\Abstracts\AbstractConnection
83
     */
84
    public function &createConnection($connectionOffset, DataStructures\Config $connectionConfig)
85
    {
86
        $driverMaps = [
87
            'mongodb' => '\O2System\Database\NoSql\Drivers\MongoDb\Connection',
88
            'mysql'   => '\O2System\Database\Sql\Drivers\MySql\Connection',
89
            'sqlite'  => '\O2System\Database\Sql\Drivers\Sqlite\Connection',
90
        ];
91
92
        if (array_key_exists($connectionConfig->driver, $driverMaps)) {
0 ignored issues
show
Bug Best Practice introduced by
The property driver does not exist on O2System\Database\DataStructures\Config. Since you implemented __get, consider adding a @property annotation.
Loading history...
93
            if (class_exists($driverClassName = $driverMaps[ $connectionConfig->driver ])) {
94
                $driverInstance = new $driverClassName($connectionConfig);
95
                $this->register($driverInstance, $connectionOffset);
96
            }
97
98
            return $this->getObject($connectionOffset);
99
        }
100
101
        return false;
102
    }
103
104
    // ------------------------------------------------------------------------
105
106
    /**
107
     * Connections::validate
108
     *
109
     * Determine if value is meet requirement.
110
     *
111
     * @param mixed $value
112
     *
113
     * @return bool
114
     */
115
    public function validate($value)
116
    {
117
        if ($value instanceof \O2System\Database\Sql\Abstracts\AbstractConnection || $value instanceof \O2System\Database\NoSql\Abstracts\AbstractConnection) {
118
            return true;
119
        }
120
121
        return false;
122
    }
123
}