Completed
Push — master ( 66cd91...6aa991 )
by Gabriel
01:42
created

MvcServiceProvider::createModulesProvider()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 4.125

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 5
c 1
b 0
f 1
nc 3
nop 0
dl 0
loc 10
ccs 3
cts 6
cp 0.5
crap 4.125
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 Modules
55
     */
56 1
    protected function createSectionsManager()
57
    {
58 1
        $sections = $this->getContainer()->has(SectionsManager::class) ?
59 1
            $this->getContainer()->get(SectionsManager::class)
60 1
            : new SectionsManager();
61 1
        $sections->init();
0 ignored issues
show
Deprecated Code introduced by
The function Nip\Mvc\Sections\SectionsManager::init() has been deprecated: no need to call init ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

61
        /** @scrutinizer ignore-deprecated */ $sections->init();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
62 1
        return $sections;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $sections also could return the type Nip\Mvc\Sections\SectionsManager which is incompatible with the documented return type Nip\Mvc\Modules.
Loading history...
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68
    public function provides()
69
    {
70
        return ['mvc.modules', 'mvc.sections'];
71
    }
72
}
73