Test Failed
Push — master ( 9fdf3e...42dea4 )
by Mikael
01:22
created

CDIFactoryDefault::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 114
Code Lines 80

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 114
rs 8.2857
c 0
b 0
f 0
cc 1
eloc 80
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Anax\DI;
4
5
/**
6
 * Anax base class implementing Dependency Injection / Service Locator
7
 * of the services used by the framework, using lazy loading.
8
 */
9
class CDIFactoryDefault extends CDI
10
{
11
    use \Anax\TLoadFile;
12
13
14
15
   /**
16
     * Construct.
17
     *
18
     */
19
    public function __construct()
20
    {
21
        parent::__construct();
22
23
        $this->loadFile("error_reporting.php");
24
25
        $this->setShared("response", "\Anax\Response\CResponseBasic");
26
        $this->setShared("validate", "\Anax\Validate\CValidate");
27
        $this->setShared("flash", "\Anax\Flash\CFlashBasic");
28
        $this->setShared("textFilter", "\Mos\TextFilter\CTextFilter");
29
30
        $this->set("route", "\Anax\Route\CRouteBasic");
31
        $this->set("view", "\Anax\View\CView");
32
33
        $this->set("ErrorController", function () {
34
            $controller = new \Anax\MVC\ErrorController();
35
            $controller->setDI($this);
36
            return $controller;
37
        });
38
39
        $this->setShared("log", function () {
40
            $log = new \Anax\Log\CLogger();
41
            $log->setContext("development");
42
            return $log;
43
        });
44
45
        $this->setShared("cache", function () {
46
            $cache = new \Anax\Cache\CFileCache();
47
            $cache->configure("cache.php");
48
            return $cache;
49
        });
50
51
        $this->setShared("request", function () {
52
            $request = new \Anax\Request\CRequestBasic();
53
            $request->init();
54
            return $request;
55
        });
56
57
        $this->setShared("url", function () {
58
            $url = new \Anax\Url\CUrl();
59
            $url->configure("url.php");
60
            $url->setSiteUrl($this->request->getSiteUrl());
61
            $url->setBaseUrl($this->request->getBaseUrl());
62
            $url->setStaticSiteUrl($this->request->getSiteUrl());
63
            $url->setStaticBaseUrl($this->request->getBaseUrl());
64
            $url->setScriptName($this->request->getScriptName());
65
            $url->setDefaultsFromConfiguration();
66
            return $url;
67
        });
68
69
        $this->setShared("views", function () {
70
            $views = new \Anax\View\CViewContainer();
71
            $views->configure("views.php");
72
            $views->setDI($this);
73
            return $views;
74
        });
75
76
        $this->setShared("router", function () {
77
            
78
            $router = new \Anax\Route\CRouterBasic();
79
            $router->setDI($this);
80
            return $router;
81
        });
82
83
        $this->setShared("dispatcher", function () {
84
            $dispatcher = new \Anax\MVC\CDispatcherBasic();
85
            $dispatcher->setDI($this);
86
            return $dispatcher;
87
        });
88
89
        $this->setShared("session", function () {
90
            $session = new \Anax\Session\CSession();
91
            $session->configure("session.php");
92
            $session->name();
93
            $session->start();
94
            return $session;
95
        });
96
97
        $this->setShared("theme", function () {
98
            $themeEngine = new \Anax\ThemeEngine\CThemeEngine();
99
            $themeEngine->setDI($this);
100
            $themeEngine->configure("theme.php");
101
            return $themeEngine;
102
        });
103
104
        $this->setShared("navbar", function () {
105
            $navbar = new \Anax\Navigation\CNavbar();
106
            $navbar->setDI($this);
107
            $navbar->configure("navbar.php");
108
            return $navbar;
109
        });
110
111
        $this->set("fileContent", function () {
112
            $fc = new \Anax\Content\CFileContent();
113
            $fc->setDI($this);
114
            $fc->configure("file_content.php");
115
            return $fc;
116
        });
117
118
        $this->set("pageContent", function () {
119
            $pc = new \Anax\Content\CPageContent();
120
            $pc->setDI($this);
121
            $pc->configure("page_content.php");
122
            return $pc;
123
        });
124
125
        $this->setShared("content", function () {
126
            $content = new \Anax\Content\CFileBasedContent();
127
            $content->setDI($this);
128
            $content->configure("content.php");
129
            $content->setDefaultsFromConfiguration();
130
            return $content;
131
        });
132
    }
133
}
134