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.
Passed
Push — master ( 9c3470...c852c0 )
by
unknown
02:52
created

Models::load()   A

Complexity

Conditions 6
Paths 9

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 8
nc 9
nop 2
dl 0
loc 14
rs 9.2222
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the O2System PHP 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\Framework\Containers;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Database;
19
use O2System\Framework\Models\Files\Model as FileModel;
20
use O2System\Framework\Models\NoSql\Model as NoSqlModel;
21
use O2System\Framework\Models\Sql\Model as SqlModel;
22
use O2System\Spl\Containers\Datastructures\SplServiceRegistry;
23
use O2System\Spl\Containers\SplServiceContainer;
24
25
/**
26
 * Class Models
27
 *
28
 * @package O2System\Framework
29
 */
30
class Models extends SplServiceContainer
31
{
32
    public $database;
33
34
    /**
35
     * Models::__construct
36
     */
37
    public function __construct()
38
    {
39
        if ($config = config()->loadFile('database', true)) {
0 ignored issues
show
Bug introduced by
The method loadFile() does not exist on O2System\Kernel\Datastructures\Config. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        if ($config = config()->/** @scrutinizer ignore-call */ loadFile('database', true)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
            if ( ! empty($config[ 'default' ][ 'hostname' ]) AND ! empty($config[ 'default' ][ 'username' ])) {
41
42
                if(profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
43
                    profiler()->watch('Starting Database Service');
44
                }
45
46
                $this->database = new Database\Connections(
47
                    new Database\Datastructures\Config(
48
                        $config->getArrayCopy()
49
                    )
50
                );
51
            }
52
        }
53
    }
54
55
    // ------------------------------------------------------------------------
56
57
    /**
58
     * Models::load
59
     *
60
     * @param object|string $model
61
     * @param string|null   $offset
62
     */
63
    public function load($model, $offset = null)
64
    {
65
        if (is_string($model)) {
66
            $service = new SplServiceRegistry($model);
67
        } elseif ($model instanceof SplServiceRegistry) {
68
            $service = $model;
69
        }
70
71
        if (isset($service) && $service instanceof SplServiceRegistry) {
72
            if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
73
                profiler()->watch('Load New Model: ' . $service->getClassName());
74
            }
75
76
            $this->register($service, $offset);
77
        }
78
    }
79
80
    // ------------------------------------------------------------------------
81
82
    /**
83
     * Models::add
84
     *
85
     * @param \O2System\Framework\Models\Sql\Model|\O2System\Framework\Models\NoSql\Model|\O2System\Framework\Models\Files\Model $model
86
     * @param null $offset
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $offset is correct as it would always require null to be passed?
Loading history...
87
     */
88
    public function add($model, $offset = null)
89
    {
90
        if (is_object($service)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $service seems to be never defined.
Loading history...
91
            if ( ! $service instanceof SplServiceRegistry) {
92
                $service = new SplServiceRegistry($service);
93
            }
94
        }
95
96
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
97
            profiler()->watch('Add New Model: ' . $service->getClassName());
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $service does not seem to be defined for all execution paths leading up to this point.
Loading history...
98
        }
99
100
        $this->register($service, $offset);
101
    }
102
103
    // ------------------------------------------------------------------------
104
105
    /**
106
     * Models::register
107
     *
108
     * @param SplServiceRegistry $service
109
     * @param string|null        $offset
110
     */
111
    public function register(SplServiceRegistry $service, $offset = null)
112
    {
113
        if ($service instanceof SplServiceRegistry) {
0 ignored issues
show
introduced by
$service is always a sub-type of O2System\Spl\Containers\...ures\SplServiceRegistry.
Loading history...
114
            $offset = isset($offset)
115
                ? $offset
116
                : camelcase($service->getParameter());
117
118
            if ($service->isSubclassOf('O2System\Framework\Models\Sql\Model') ||
119
                $service->isSubclassOf('O2System\Framework\Models\NoSql\Model') ||
120
                $service->isSubclassOf('O2System\Framework\Models\Files\Model')
121
            ) {
122
                $this->attach($offset, $service);
123
124
                if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
125
                    profiler()->watch('Register New Model: ' . $service->getClassName());
126
                }
127
            }
128
        }
129
    }
130
}