| Conditions | 12 |
| Paths | 9 |
| Total Lines | 61 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 145 | public function &get($offset, array $arguments = []) |
||
| 146 | {
|
||
| 147 | $get[ $offset ] = false; |
||
| 148 | |||
| 149 | if ($this->has($offset)) {
|
||
| 150 | $service = $this->services[ $offset ]; |
||
| 151 | |||
| 152 | if ($service instanceof SplServiceRegistry) {
|
||
| 153 | if (empty($arguments)) {
|
||
| 154 | return $service->getInstance(); |
||
| 155 | } else {
|
||
| 156 | if ($service->hasMethod('__construct')) {
|
||
| 157 | $newServiceInstance = $service->newInstanceArgs($arguments); |
||
| 158 | } else {
|
||
| 159 | $newServiceInstance = $service->getInstance(); |
||
| 160 | } |
||
| 161 | |||
| 162 | if ($DocComment = $service->getDocComment()) {
|
||
| 163 | preg_match_all('/@inject\s(.*)/', $DocComment, $matches);
|
||
| 164 | |||
| 165 | if (count($matches[ 1 ])) {
|
||
| 166 | foreach ($matches[ 1 ] as $className) {
|
||
| 167 | $className = trim($className, '\\'); |
||
| 168 | $className = trim($className); |
||
| 169 | |||
| 170 | $map = strtolower(get_class_name($className)); |
||
| 171 | |||
| 172 | if (isset($this->map[ $className ])) {
|
||
| 173 | $map = $this->map[ $className ]; |
||
| 174 | } |
||
| 175 | |||
| 176 | $variable = $map; |
||
| 177 | $object =& $this->get($map); |
||
| 178 | |||
| 179 | preg_match_all('/[$](.*)\s(.*)/', trim($className), $classMatches);
|
||
| 180 | |||
| 181 | if (count($classMatches[ 1 ])) {
|
||
| 182 | $variable = $classMatches[ 1 ][ 0 ]; |
||
| 183 | } |
||
| 184 | |||
| 185 | $setterMethod = ucwords(str_replace(['-', '_'], ' ', $variable)); |
||
| 186 | $setterMethod = str_replace(' ', '', $setterMethod);
|
||
| 187 | $setterMethod = 'set' . $setterMethod; |
||
| 188 | |||
| 189 | if (method_exists($newServiceInstance, $setterMethod)) {
|
||
| 190 | $newServiceInstance->{$setterMethod}($object);
|
||
| 191 | } elseif (method_exists($newServiceInstance, '__set')) {
|
||
| 192 | $newServiceInstance->__set($variable, $object); |
||
| 193 | } else {
|
||
| 194 | $newServiceInstance->{$variable} =& $object;
|
||
| 195 | } |
||
| 196 | } |
||
| 197 | } |
||
| 198 | } |
||
| 199 | |||
| 200 | $get[ $offset ] = $newServiceInstance; |
||
| 201 | } |
||
| 202 | } |
||
| 203 | } |
||
| 204 | |||
| 205 | return $get[ $offset ]; |
||
| 206 | } |
||
| 226 | } |