Passed
Push — master ( 47699c...d74cf0 )
by Rougin
01:47
created

ZapheusProvider::merge()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0438

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 11
ccs 7
cts 9
cp 0.7778
crap 2.0438
rs 9.4285
1
<?php
2
3
namespace App\Zapheus;
4
5
use Zapheus\Container\WritableInterface;
6
use Zapheus\Provider\ProviderInterface;
7
use Zapheus\Routing\RouterInterface;
8
9
/**
10
 * Zapheus Provider
11
 *
12
 * @package App
13
 * @author  Rougin Royce Gutib <[email protected]>
14
 */
15
class ZapheusProvider implements ProviderInterface
16
{
17
    const COMPOSITE = 'App\Zapheus\CompositeRouter';
18
19
    /**
20
     * Registers the bindings in the container.
21
     *
22
     * @param  \Zapheus\Container\WritableInterface $container
23
     * @return \Zapheus\Container\ContainerInterface
24
     */
25 6
    public function register(WritableInterface $container)
26
    {
27 6
        return self::merge($container, new RouteCollection);
28
    }
29
30
    /**
31
     * Merges two or more Routing\RouterInterface instances.
32
     *
33
     * @param  \Zapheus\Container\WritableInterface $container
34
     * @param  \Zapheus\Routing\RouterInterface     $router
35
     * @return \Zapheus\Container\WritableInterface
36
     */
37 6
    public static function merge(WritableInterface $container, RouterInterface $router)
38
    {
39 6
        if ($container->has(self::COMPOSITE)) {
40 6
            $composite = $container->get(self::COMPOSITE);
41
42 6
            $composite->merge($router);
43 6
        } else {
44 6
            $composite = (new CompositeRouter)->merge($router);
45
        }
46
47 6
        return $container->set(self::COMPOSITE, $composite);
48
    }
49
}
50