InstanceBinding   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A resolve() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cakasim\Payone\Sdk\Container\Binding;
6
7
use Cakasim\Payone\Sdk\Container\ContainerException;
8
9
/**
10
 * A binding that uses an instance as
11
 * underlying value.
12
 *
13
 * @author Fabian Böttcher <[email protected]>
14
 * @since 0.1.0
15
 */
16
class InstanceBinding implements BindingInterface
17
{
18
    /**
19
     * @var object The instance to use as underlying value.
20
     */
21
    protected $concrete;
22
23
    /**
24
     * Constructs the InstanceBinding.
25
     *
26
     * @param string $abstract The class / interface type the concrete is bound to.
27
     * @param object $concrete The instance which is a concrete of abstract.
28
     *
29
     * @throws ContainerException If concrete does not satisfy the requirements.
30
     */
31
    public function __construct(string $abstract, $concrete)
32
    {
33
        if (!is_object($concrete)) {
34
            throw new ContainerException("Cannot create binding for '{$abstract}', the provided concrete must be an object.");
35
        }
36
37
        if (!($concrete instanceof $abstract)) {
38
            throw new ContainerException("Cannot create binding for '{$abstract}', the provided concrete must be an instance of '{$abstract}'.");
39
        }
40
41
        $this->concrete = $concrete;
42
    }
43
44
    /**
45
     * @inheritDoc
46
     */
47
    public function resolve()
48
    {
49
        return $this->concrete;
50
    }
51
}
52