Completed
Push — master ( f8d1bb...25dd19 )
by Elf
01:40
created

MacroRegistrar::register()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
nc 3
nop 3
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 3
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace ElfSundae\Laravel\Apps;
4
5
use Illuminate\Contracts\Container\Container;
6
7
class MacroRegistrar
8
{
9
    /**
10
     * Register needed macros.
11
     *
12
     * @param  \Illuminate\Contracts\Container\Container  $container
13
     * @return void
14
     */
15 4
    public function registerMacros(Container $container)
16
    {
17 4
        $this->register(
18 4
            $container['url'],
19 4
            'getRootControllerNamespace',
20 4
            function () {
21 2
                return $this->rootNamespace;
22 4
            }
23
        );
24
25 4
        $this->register(
26 4
            $container['router'],
27 4
            'hasMiddlewareGroup',
28 4
            function ($name) {
29
                return array_key_exists($name, $this->middlewareGroups);
30 4
            }
31
        );
32 4
    }
33
34
    /**
35
     * Register a macro to the class.
36
     *
37
     * @param  string|object  $class
38
     * @param  string  $method
39
     * @param  object|callable  $macro
40
     * @return void
41
     */
42 5
    public function register($class, $method, $macro)
43
    {
44 5
        if (! method_exists($class, $method)) {
45 5
            $class = is_object($class) ? get_class($class) : $class;
46
47 5
            call_user_func_array([$class, 'macro'], [$method, $macro]);
48
        }
49 5
    }
50
}
51