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.

Services::add()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
c 2
b 0
f 0
nc 6
nop 2
dl 0
loc 13
rs 10
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\Kernel\Containers;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Spl\Containers\DataStructures\SplServiceRegistry;
19
use O2System\Spl\Containers\SplServiceContainer;
20
21
/**
22
 * Class Services
23
 *
24
 * @package O2System\Framework
25
 */
26
class Services extends SplServiceContainer
27
{
28
    /**
29
     * Services::load
30
     *
31
     * @param string      $className
32
     * @param string|null $offset
33
     */
34
    public function load($className, $offset = null)
35
    {
36
        if (is_string($className)) {
0 ignored issues
show
introduced by
The condition is_string($className) is always true.
Loading history...
37
            $className = str_replace([
38
                'O2System\Framework\\',
39
                'O2System\Reactor\\',
40
                'O2System\Kernel\\',
41
                'App\\',
42
            ], '',
43
                ltrim($className, '\\')
44
            );
45
46
            if (class_exists($className)) {
47
                $service = new SplServiceRegistry($className);
48
            } else {
49
                if (is_object(kernel()->modules)) {
0 ignored issues
show
Bug Best Practice introduced by
The property modules does not exist on O2System\Kernel. Since you implemented __get, consider adding a @property annotation.
Loading history...
50
                    if ($module = kernel()->modules->top()) {
51
                        if (class_exists($serviceClassName = $module->getNamespace() . $className)) {
52
                            $service = new SplServiceRegistry($serviceClassName);
53
                        }
54
                    }
55
                }
56
57
                if (empty($service)) {
58
                    if (class_exists($serviceClassName = 'App\\' . $className)) {
59
                        $service = new SplServiceRegistry($serviceClassName);
60
                    } elseif (class_exists($serviceClassName = 'O2System\Framework\\' . $className)) {
61
                        $service = new SplServiceRegistry($serviceClassName);
62
                    } elseif (class_exists($serviceClassName = 'O2System\Reactor\\' . $className)) {
63
                        $service = new SplServiceRegistry($serviceClassName);
64
                    } elseif (class_exists($serviceClassName = 'O2System\Kernel\\' . $className)) {
65
                        $service = new SplServiceRegistry($serviceClassName);
66
                    } elseif(class_exists($className)) {
67
                        $service = new SplServiceRegistry($serviceClassName);
68
                    }
69
                }
70
            }
71
        }
72
73
        if (isset($service)) {
74
            if ($service instanceof SplServiceRegistry) {
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...
75
                if (profiler() !== false) {
76
                    profiler()->watch('Load New Service: ' . $service->getClassName());
77
                }
78
79
                $this->register($service, $offset);
80
            }
81
        }
82
    }
83
84
    // ------------------------------------------------------------------------
85
86
    /**
87
     * Services::register
88
     *
89
     * @param SplServiceRegistry $service
90
     * @param string|null        $offset
91
     */
92
    public function register(SplServiceRegistry $service, $offset = null)
93
    {
94
        if ($service instanceof SplServiceRegistry) {
0 ignored issues
show
introduced by
$service is always a sub-type of O2System\Spl\Containers\...ures\SplServiceRegistry.
Loading history...
95
            $offset = isset($offset)
96
                ? $offset
97
                : camelcase($service->getParameter());
98
99
            $this->attach($offset, $service);
100
101
            if (profiler() !== false) {
102
                profiler()->watch('Register New Service: ' . $service->getClassName());
103
            }
104
        }
105
    }
106
107
    // ------------------------------------------------------------------------
108
109
    /**
110
     * Services::add
111
     *
112
     * @param object      $service
113
     * @param string|null $offset
114
     */
115
    public function add($service, $offset = null)
116
    {
117
        if (is_object($service)) {
118
            if ( ! $service instanceof SplServiceRegistry) {
119
                $service = new SplServiceRegistry($service);
120
            }
121
        }
122
123
        if (profiler() !== false) {
124
            profiler()->watch('Add New Service: ' . $service->getClassName());
125
        }
126
127
        $this->register($service, $offset);
128
    }
129
}