| Conditions | 5 |
| Paths | 1 |
| Total Lines | 110 |
| Code Lines | 70 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
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 |
||
| 117 | public function getServices() |
||
| 118 | { |
||
| 119 | $this->container = parent::getServices(); |
||
|
|
|||
| 120 | $this->container['db'] = function ($c) { |
||
| 121 | $db = new Db(); |
||
| 122 | $db->setCredentials($this->getDbConfig()); |
||
| 123 | $type = 'pdo'; |
||
| 124 | if( function_exists('mysqli_select_db')) |
||
| 125 | { |
||
| 126 | $type = 'mysqli'; |
||
| 127 | } |
||
| 128 | |||
| 129 | $db->setAccessType($type); |
||
| 130 | return $db; |
||
| 131 | }; |
||
| 132 | |||
| 133 | $this->container['encrypt'] = function ($c) { |
||
| 134 | $encrypt = new Encrypt(); |
||
| 135 | $new_key = $c['platform']->getEncryptionKey(); |
||
| 136 | $encrypt->setKey($new_key); |
||
| 137 | return $encrypt; |
||
| 138 | }; |
||
| 139 | |||
| 140 | $this->container['lang'] = function ($c) { |
||
| 141 | $lang = new Language(); |
||
| 142 | if (is_array($this->getLangPath())) { |
||
| 143 | foreach ($this->getLangPath() as $path) { |
||
| 144 | $lang->init($path); |
||
| 145 | } |
||
| 146 | } elseif ($this->getLangPath() != '') { |
||
| 147 | $lang->init($this->getLangPath()); |
||
| 148 | } |
||
| 149 | return $lang; |
||
| 150 | }; |
||
| 151 | |||
| 152 | $this->container['validate'] = function ($c) { |
||
| 153 | $validate = new Validate(); |
||
| 154 | $validate->setRegex($this->container['regex']); |
||
| 155 | return $validate; |
||
| 156 | }; |
||
| 157 | |||
| 158 | $this->container['files'] = function ($c) { |
||
| 159 | $file = new Files(); |
||
| 160 | return $file; |
||
| 161 | }; |
||
| 162 | |||
| 163 | $this->container['errors'] = function ($c) { |
||
| 164 | $errors = new Errors(); |
||
| 165 | $errors->setValidation($c['validate']); |
||
| 166 | return $errors; |
||
| 167 | }; |
||
| 168 | |||
| 169 | $this->container['license'] = function ($c) { |
||
| 170 | $license = new License(); |
||
| 171 | return $license; |
||
| 172 | }; |
||
| 173 | |||
| 174 | $this->container['email'] = function ($c) { |
||
| 175 | |||
| 176 | $email = new Email(); |
||
| 177 | $email->setView($c['view']); |
||
| 178 | $email->setLang($c['lang']); |
||
| 179 | return $email; |
||
| 180 | }; |
||
| 181 | |||
| 182 | $this->container['view'] = function ($c) { |
||
| 183 | $view = new View(); |
||
| 184 | $helpers = array( |
||
| 185 | 'file_size' => function ($text) { |
||
| 186 | return $this->container['view_helpers']->m62FileSize($text, false); |
||
| 187 | }, |
||
| 188 | 'lang' => function ($text) { |
||
| 189 | return $this->container['view_helpers']->m62Lang($text); |
||
| 190 | }, |
||
| 191 | 'date_time' => function ($text, $html = true) { |
||
| 192 | return $this->container['view_helpers']->m62DateTime($text, false); |
||
| 193 | }, |
||
| 194 | 'relative_time' => function ($date) { |
||
| 195 | return $this->container['view_helpers']->m62RelativeDateTime($date); |
||
| 196 | }, |
||
| 197 | 'encode' => function ($text) { |
||
| 198 | return $this->container['view_helpers']->m62Encode($text); |
||
| 199 | }, |
||
| 200 | 'decode' => function ($text) { |
||
| 201 | return $this->container['view_helpers']->m62Decode($text); |
||
| 202 | } |
||
| 203 | ); |
||
| 204 | |||
| 205 | $view->addHelper('m62', $helpers); |
||
| 206 | return $view; |
||
| 207 | }; |
||
| 208 | |||
| 209 | $this->container['regex'] = function ($c) { |
||
| 210 | $regex = new Regex(); |
||
| 211 | return $regex; |
||
| 212 | }; |
||
| 213 | |||
| 214 | $this->container['shell'] = function ($c) { |
||
| 215 | $shell = new Shell(); |
||
| 216 | return $shell; |
||
| 217 | }; |
||
| 218 | |||
| 219 | $this->container['console'] = function ($c) { |
||
| 220 | $console = new Console(); |
||
| 221 | $console->setLang($c['lang']); |
||
| 222 | return $console; |
||
| 223 | }; |
||
| 224 | |||
| 225 | return $this->container; |
||
| 226 | } |
||
| 227 | } |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.