Completed
Push — master ( 6aa991...37aa33 )
by Gabriel
02:02
created

MvcServiceProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 16
c 2
b 0
f 1
dl 0
loc 58
ccs 18
cts 24
cp 0.75
rs 10
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A createModulesProvider() 0 10 3
A registerSections() 0 4 1
A registerModules() 0 4 1
A provides() 0 3 1
A createSectionsManager() 0 7 2
1
<?php
2
3
namespace Nip\Mvc;
4
5
use Nip\Container\ServiceProviders\Providers\AbstractSignatureServiceProvider;
6
use Nip\Mvc\Modules\ModulesManager;
7
use Nip\Mvc\Sections\SectionsManager;
8
9
/**
10
 * Class MvcServiceProvider
11
 * @package Nip\Mvc
12
 */
13
class MvcServiceProvider extends AbstractSignatureServiceProvider
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18 1
    public function register()
19
    {
20 1
        $this->registerModules();
21 1
        $this->registerSections();
22 1
    }
23
24 1
    protected function registerModules()
25
    {
26
        $this->getContainer()->share('mvc.modules', function () {
27 1
            return $this->createModulesProvider();
28 1
        });
29 1
    }
30
31
    /**
32
     * @return ModulesManager
33
     */
34 1
    protected function createModulesProvider()
35
    {
36 1
        if ($this->getContainer()->has(Modules::class)) {
37 1
            return $this->getContainer()->get(Modules::class);
38
        }
39
        if ($this->getContainer()->has(ModulesManager::class)) {
40
            return $this->getContainer()->get(ModulesManager::class);
41
        }
42
43
        return new ModulesManager();
44
    }
45
46 1
    protected function registerSections()
47
    {
48
        $this->getContainer()->share('mvc.sections', function () {
49 1
            return $this->createSectionsManager();
50 1
        });
51 1
    }
52
53
    /**
54
     * @return SectionsManager
55
     */
56 1
    protected function createSectionsManager()
57
    {
58 1
        if ($this->getContainer()->has(SectionsManager::class)) {
59 1
            return $this->getContainer()->get(SectionsManager::class);
60
        }
61
62
        return new SectionsManager();
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68
    public function provides()
69
    {
70
        return ['mvc.modules', 'mvc.sections'];
71
    }
72
}
73