LaravelBinderAdapter   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A bind() 0 8 3
A bindSingleton() 0 12 4
A bindToInstance() 0 4 1
1
<?php
2
/*
3
 * Copyright (c) 2015 Juan José Torroglosa Ramón
4
 *
5
 * This file is part of the Cliphar package.
6
 *
7
 * For the full copyright and license information, please view
8
 * the LICENSE file that was distributed with this source code.
9
 */
10
11
namespace Cliphar\Container\Laravel;
12
13
use Cliphar\Binder;
14
use Cliphar\Container\Exception\ContainerException;
15
use Illuminate\Container\Container as LaravelContainer;
16
17
18
/**
19
 * Class LaravelBinderAdapter 
20
 */
21
class LaravelBinderAdapter implements Binder
22
{
23
    /**
24
     * @var LaravelContainer
25
     */
26
    private $container;
27
28
    public function __construct(LaravelContainer $container)
29
    {
30
        $this->container = $container;
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36
    public function bind($abstract, $concrete)
37
    {
38
        if ($concrete instanceof \Closure || is_string($concrete)) {
39
            $this->container->bind($abstract, $concrete);
40
        } else {
41
            throw new ContainerException("Invalid parameter. This method only accepts Closure or string for \$to parameter");
42
        }
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function bindSingleton($abstract, $concrete)
49
    {
50
        if ($concrete instanceof \Closure) {
51
            $this->container->bindShared($abstract, $concrete);
52
        } else if (is_object($concrete)) {
53
            $this->container->instance($abstract, $concrete);
54
        } else if (is_string($concrete)) {
55
            $this->container->singleton($abstract, $concrete);
56
        } else {
57
            throw new ContainerException("Invalid parameter. This method only accepts Closure, string or object \$to parameter");
58
        }
59
    }
60
61
    /**
62
     * @inheritdoc
63
     */
64
    public function bindToInstance($abstract, $instance)
65
    {
66
        $this->container->instance($abstract, $instance);
67
    }
68
}