| Conditions | 5 |
| Paths | 1 |
| Total Lines | 109 |
| Code Lines | 70 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 = 'mysqli'; |
||
| 124 | if(class_exists('Pdo')) { |
||
| 125 | $type = 'pdo'; |
||
| 126 | } |
||
| 127 | |||
| 128 | $db->setAccessType($type); |
||
| 129 | return $db; |
||
| 130 | }; |
||
| 131 | |||
| 132 | $this->container['encrypt'] = function ($c) { |
||
| 133 | $encrypt = new Encrypt(); |
||
| 134 | $new_key = $c['platform']->getEncryptionKey(); |
||
| 135 | $encrypt->setKey($new_key); |
||
| 136 | return $encrypt; |
||
| 137 | }; |
||
| 138 | |||
| 139 | $this->container['lang'] = function ($c) { |
||
| 140 | $lang = new Language(); |
||
| 141 | if (is_array($this->getLangPath())) { |
||
| 142 | foreach ($this->getLangPath() as $path) { |
||
| 143 | $lang->init($path); |
||
| 144 | } |
||
| 145 | } elseif ($this->getLangPath() != '') { |
||
| 146 | $lang->init($this->getLangPath()); |
||
| 147 | } |
||
| 148 | return $lang; |
||
| 149 | }; |
||
| 150 | |||
| 151 | $this->container['validate'] = function ($c) { |
||
| 152 | $validate = new Validate(); |
||
| 153 | $validate->setRegex($this->container['regex']); |
||
| 154 | return $validate; |
||
| 155 | }; |
||
| 156 | |||
| 157 | $this->container['files'] = function ($c) { |
||
| 158 | $file = new Files(); |
||
| 159 | return $file; |
||
| 160 | }; |
||
| 161 | |||
| 162 | $this->container['errors'] = function ($c) { |
||
| 163 | $errors = new Errors(); |
||
| 164 | $errors->setValidation($c['validate']); |
||
| 165 | return $errors; |
||
| 166 | }; |
||
| 167 | |||
| 168 | $this->container['license'] = function ($c) { |
||
| 169 | $license = new License(); |
||
| 170 | return $license; |
||
| 171 | }; |
||
| 172 | |||
| 173 | $this->container['email'] = function ($c) { |
||
| 174 | |||
| 175 | $email = new Email(); |
||
| 176 | $email->setView($c['view']); |
||
| 177 | $email->setLang($c['lang']); |
||
| 178 | return $email; |
||
| 179 | }; |
||
| 180 | |||
| 181 | $this->container['view'] = function ($c) { |
||
| 182 | $view = new View(); |
||
| 183 | $helpers = array( |
||
| 184 | 'file_size' => function ($text) { |
||
| 185 | return $this->container['view_helpers']->m62FileSize($text, false); |
||
| 186 | }, |
||
| 187 | 'lang' => function ($text) { |
||
| 188 | return $this->container['view_helpers']->m62Lang($text); |
||
| 189 | }, |
||
| 190 | 'date_time' => function ($text, $html = true) { |
||
| 191 | return $this->container['view_helpers']->m62DateTime($text, false); |
||
| 192 | }, |
||
| 193 | 'relative_time' => function ($date) { |
||
| 194 | return $this->container['view_helpers']->m62RelativeDateTime($date); |
||
| 195 | }, |
||
| 196 | 'encode' => function ($text) { |
||
| 197 | return $this->container['view_helpers']->m62Encode($text); |
||
| 198 | }, |
||
| 199 | 'decode' => function ($text) { |
||
| 200 | return $this->container['view_helpers']->m62Decode($text); |
||
| 201 | } |
||
| 202 | ); |
||
| 203 | |||
| 204 | $view->addHelper('m62', $helpers); |
||
| 205 | return $view; |
||
| 206 | }; |
||
| 207 | |||
| 208 | $this->container['regex'] = function ($c) { |
||
| 209 | $regex = new Regex(); |
||
| 210 | return $regex; |
||
| 211 | }; |
||
| 212 | |||
| 213 | $this->container['shell'] = function ($c) { |
||
| 214 | $shell = new Shell(); |
||
| 215 | return $shell; |
||
| 216 | }; |
||
| 217 | |||
| 218 | $this->container['console'] = function ($c) { |
||
| 219 | $console = new Console(); |
||
| 220 | $console->setLang($c['lang']); |
||
| 221 | return $console; |
||
| 222 | }; |
||
| 223 | |||
| 224 | return $this->container; |
||
| 225 | } |
||
| 226 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.