Completed
Push — master ( 0aa73e...51b902 )
by Elf
01:47
created

MacroRegistrar   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
dl 0
loc 46
ccs 18
cts 19
cp 0.9474
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 8 3
A registerMacros() 0 20 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 7
    public function registerMacros(Container $container)
16
    {
17 7
        $this->register(
18 7
            $container['url'],
19 7
            'getRootControllerNamespace',
20 7
            function () {
21
                /* @var $this \Illuminate\Routing\UrlGenerator */
22 2
                return $this->rootNamespace;
23 7
            }
24
        );
25
26 7
        $this->register(
27 7
            $container['router'],
28 7
            'hasMiddlewareGroup',
29 7
            function ($name) {
30
                /* @var $this \Illuminate\Routing\Router */
31
                return array_key_exists($name, $this->middlewareGroups);
32 7
            }
33
        );
34 7
    }
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 8
    public function register($class, $method, $macro)
45
    {
46 8
        if (! method_exists($class, $method)) {
47 8
            $class = is_object($class) ? get_class($class) : $class;
48
49 8
            call_user_func_array([$class, 'macro'], [$method, $macro]);
50
        }
51 8
    }
52
}
53