LaravelRegistrar::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
nc 1
cc 1
eloc 2
nop 1
crap 1
1
<?php
2
3
namespace Alfheim\Sanitizer\Registrar;
4
5
use Illuminate\Contracts\Container\Container;
6
7
class LaravelRegistrar extends BaseRegistrar
8
{
9
    /** @var \Illuminate\Contracts\Container\Container */
10
    private $container;
11
12
    /**
13
     * Create a new Laravel registrar instance.
14
     *
15
     * @param  \Illuminate\Contracts\Container\Container  $container
16
     */
17 12
    public function __construct(Container $container)
18
    {
19 12
        $this->container = $container;
20 12
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 12
    public function resolve($name)
26
    {
27 12
        $value = $this->registrations[$name];
28
29 12
        if (is_string($value)) {
30
            // Check for `class@method` format.
31 12
            if (strpos($value, '@') >= 1) {
32 4
                $segments = explode('@', $value, 2);
33
34 4
                if ($this->container->bound($segments[0])) {
35
                    return [
36 4
                        $this->container->make($segments[0]), $segments[1],
37 3
                    ];
38
                }
39
            }
40
41 8
            if ($this->container->bound($name)) {
42 4
                return $this->container->make($name);
43
            }
44 3
        }
45
46 4
        return parent::resolve($name);
47
    }
48
}
49