LaravelRegistrar::resolve()   B
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5.0113

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
ccs 12
cts 13
cp 0.9231
rs 8.5906
nc 6
cc 5
eloc 11
nop 1
crap 5.0113
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