Completed
Push — master ( bad736...c2aae7 )
by Elf
03:15
created

MacroRegistrar   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 43
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 3
A registerMacros() 0 17 1
1
<?php
2
3
namespace ElfSundae\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 28
    public function registerMacros(Container $container)
16
    {
17 28
        $this->register(
18 28
            $container['url'],
19 28
            'getRootControllerNamespace',
20
            function () {
21
                /* @var $this \Illuminate\Routing\UrlGenerator */
22 8
                return $this->rootNamespace;
0 ignored issues
show
Bug introduced by
The property rootNamespace is declared protected in Illuminate\Routing\UrlGenerator and cannot be accessed from this context.
Loading history...
23 28
            }
24
        );
25
26 28
        $this->register(
27 28
            $container['router'],
28 28
            'hasMiddlewareGroup',
29 7
            function ($name) {
30
                /* @var $this \Illuminate\Routing\Router */
31 2
                return array_key_exists($name, $this->middlewareGroups);
0 ignored issues
show
Bug Best Practice introduced by
The property middlewareGroups does not exist on ElfSundae\Apps\MacroRegistrar. Did you maybe forget to declare it?
Loading history...
32 28
            }
33
        );
34 28
    }
35
36
    /**
37
     * Register a macro to the class.
38
     *
39
     * @param  string|object  $class
40
     * @param  string  $method
41
     * @param  object|callable  $macro
42
     * @return void
43
     */
44 32
    public function register($class, $method, $macro)
45
    {
46 32
        if (! method_exists($class, $method)) {
47 32
            $class = is_object($class) ? get_class($class) : $class;
48
49 32
            call_user_func([$class, 'macro'], $method, $macro);
50
        }
51 32
    }
52
}
53