Passed
Push — master ( 0bd6aa...0f1b31 )
by Shiyu
02:19
created

Instances::set()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 2
nc 1
nop 2
1
<?php
2
/**
3
 * Service instances
4
 * User: moyo
5
 * Date: 26/09/2017
6
 * Time: 4:14 PM
7
 */
8
9
namespace Carno\RPC\Service;
10
11
use Carno\Container\DI;
12
use Carno\RPC\Exception\ServiceInstanceNotFoundException;
13
14
class Instances
15
{
16
    /**
17
     * @param string $class
18
     * @param string|object $instance
19
     */
20
    public function set(string $class, $instance) : void
21
    {
22
        DI::set($class, is_string($instance) ? DI::object($instance) : $instance);
23
    }
24
25
    /**
26
     * @param string $class
27
     * @return object
28
     */
29
    public function get(string $class) : object
30
    {
31
        if (DI::has($class)) {
32
            return DI::get($class);
33
        } else {
34
            throw new ServiceInstanceNotFoundException($class);
35
        }
36
    }
37
}
38