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

MvcServiceProvider::createSectionsManager()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 3
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
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