Conditions | 1 |
Paths | 1 |
Total Lines | 132 |
Code Lines | 92 |
Lines | 30 |
Ratio | 22.73 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
16 | public function __construct() |
||
17 | { |
||
18 | parent::__construct(); |
||
19 | |||
20 | require ANAX_APP_PATH . 'config/error_reporting.php'; |
||
21 | |||
22 | $this->setShared('response', '\Anax\Response\CResponseBasic'); |
||
23 | $this->setShared('validate', '\Anax\Validate\CValidate'); |
||
24 | $this->setShared('flash', '\Anax\Flash\CFlashBasic'); |
||
25 | |||
26 | $this->set('route', '\Anax\Route\CRouteBasic'); |
||
27 | $this->set('view', '\Anax\View\CViewBasic'); |
||
28 | |||
29 | $this->set('ErrorController', function () { |
||
30 | $controller = new \Anax\MVC\ErrorController(); |
||
31 | $controller->setDI($this); |
||
|
|||
32 | return $controller; |
||
33 | }); |
||
34 | |||
35 | $this->setShared('log', function () { |
||
36 | $log = new \Anax\Log\CLogger(); |
||
37 | $log->setContext('development'); |
||
38 | return $log; |
||
39 | }); |
||
40 | |||
41 | $this->setShared('request', function () { |
||
42 | $request = new \Anax\Request\CRequestBasic(); |
||
43 | $request->init(); |
||
44 | return $request; |
||
45 | }); |
||
46 | |||
47 | $this->setShared('url', function () { |
||
48 | $url = new \Anax\Url\CUrl(); |
||
49 | $url->setSiteUrl($this->request->getSiteUrl()); |
||
50 | $url->setBaseUrl($this->request->getBaseUrl()); |
||
51 | $url->setStaticSiteUrl($this->request->getSiteUrl()); |
||
52 | $url->setStaticBaseUrl($this->request->getBaseUrl()); |
||
53 | $url->setScriptName($this->request->getScriptName()); |
||
54 | $url->setUrlType($url::URL_APPEND); |
||
55 | return $url; |
||
56 | }); |
||
57 | |||
58 | $this->setShared('views', function () { |
||
59 | $views = new \Anax\View\CViewContainerBasic(); |
||
60 | $views->setBasePath(ANAX_APP_PATH . 'view'); |
||
61 | $views->setFileSuffix('.tpl.php'); |
||
62 | $views->setDI($this); |
||
63 | return $views; |
||
64 | }); |
||
65 | |||
66 | $this->setShared('router', function () { |
||
67 | |||
68 | $router = new \Anax\Route\CRouterBasic(); |
||
69 | $router->setDI($this); |
||
70 | |||
71 | View Code Duplication | $router->addInternal('403', function () { |
|
72 | $this->dispatcher->forward([ |
||
73 | 'controller' => 'error', |
||
74 | 'action' => 'statusCode', |
||
75 | 'params' => [ |
||
76 | 'code' => 403, |
||
77 | 'message' => "HTTP Status Code 403: This is a forbidden route.", |
||
78 | ], |
||
79 | ]); |
||
80 | })->setName('403'); |
||
81 | |||
82 | View Code Duplication | $router->addInternal('404', function () { |
|
83 | $this->dispatcher->forward([ |
||
84 | 'controller' => 'error', |
||
85 | 'action' => 'statusCode', |
||
86 | 'params' => [ |
||
87 | 'code' => 404, |
||
88 | 'message' => "HTTP Status Code 404: This route is not found.", |
||
89 | ], |
||
90 | ]); |
||
91 | })->setName('404'); |
||
92 | |||
93 | View Code Duplication | $router->addInternal('500', function () { |
|
94 | $this->dispatcher->forward([ |
||
95 | 'controller' => 'error', |
||
96 | 'action' => 'statusCode', |
||
97 | 'params' => [ |
||
98 | 'code' => 500, |
||
99 | 'message' => "HTTP Status Code 500: There was an internal server or processing error.", |
||
100 | ], |
||
101 | ]); |
||
102 | })->setName('500'); |
||
103 | |||
104 | return $router; |
||
105 | }); |
||
106 | |||
107 | $this->setShared('dispatcher', function () { |
||
108 | $dispatcher = new \Anax\MVC\CDispatcherBasic(); |
||
109 | $dispatcher->setDI($this); |
||
110 | return $dispatcher; |
||
111 | }); |
||
112 | |||
113 | $this->setShared('session', function () { |
||
114 | $session = new \Anax\Session\CSession(); |
||
115 | $session->configure(ANAX_APP_PATH . 'config/session.php'); |
||
116 | $session->name(); |
||
117 | $session->start(); |
||
118 | return $session; |
||
119 | }); |
||
120 | |||
121 | $this->setShared('theme', function () { |
||
122 | $themeEngine = new \Anax\ThemeEngine\CThemeBasic(); |
||
123 | $themeEngine->setDI($this); |
||
124 | $themeEngine->configure(ANAX_APP_PATH . 'config/theme.php'); |
||
125 | return $themeEngine; |
||
126 | }); |
||
127 | |||
128 | $this->setShared('navbar', function () { |
||
129 | $navbar = new \Anax\Navigation\CNavbar(); |
||
130 | $navbar->setDI($this); |
||
131 | $navbar->configure(ANAX_APP_PATH . 'config/navbar.php'); |
||
132 | return $navbar; |
||
133 | }); |
||
134 | |||
135 | $this->set('fileContent', function () { |
||
136 | $fc = new \Anax\Content\CFileContent(); |
||
137 | $fc->setBasePath(ANAX_APP_PATH . 'content/'); |
||
138 | return $fc; |
||
139 | }); |
||
140 | |||
141 | $this->setShared('textFilter', function () { |
||
142 | $filter = new \Anax\Content\CTextFilter(); |
||
143 | $filter->setDI($this); |
||
144 | $filter->configure(ANAX_APP_PATH . 'config/text_filter.php'); |
||
145 | return $filter; |
||
146 | }); |
||
147 | } |
||
148 | } |
||
149 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: