ServiceLocator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
c 2
b 0
f 0
dl 0
loc 34
ccs 6
cts 6
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasService() 0 3 1
A getService() 0 3 1
A registerService() 0 3 1
1
<?php
2
/*
3
 * @author  PhileCMS
4
 * @link    https://philecms.github.io
5
 * @license http://opensource.org/licenses/MIT
6
 */
7
8
namespace Phile\Core;
9
10
use Phile\Core\Container;
11
12
/**
13
 * the Service Locator class
14
 */
15
class ServiceLocator
16
{
17
    /**
18
     * method to register a service
19
     *
20
     * @param string $serviceKey the key for the service
21
     * @param mixed  $object
22
     * @return void
23
     */
24 34
    public static function registerService(string $serviceKey, $object): void
25
    {
26 34
        Container::getInstance()->set($serviceKey, $object);
27
    }
28
29
    /**
30
     * checks if a service is registered
31
     *
32
     * @param string $serviceKey
33
     * @return bool
34
     */
35 12
    public static function hasService(string $serviceKey)
36
    {
37 12
        return Container::getInstance()->has($serviceKey);
38
    }
39
40
    /**
41
     * returns a service
42
     *
43
     * @param string $serviceKey the service key
44
     * @return mixed
45
     */
46 37
    public static function getService(string $serviceKey)
47
    {
48 37
        return Container::getInstance()->get($serviceKey);
49
    }
50
}
51