| Conditions | 19 |
| Paths | 30 |
| Total Lines | 75 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 54 | public function getMetadataForUser() |
||
| 55 | { |
||
| 56 | $reflection = new ReflectionClass($this->userClass); |
||
| 57 | $properties = $reflection->getProperties(); |
||
| 58 | $loginProperty = $passwordProperty = $apiKeyProperty = $lastActionProperty = null; |
||
| 59 | |||
| 60 | foreach ($properties as $reflectionProperty) { |
||
| 61 | foreach (array('login', 'password', 'apiKey', 'lastAction') as $annotation) { |
||
| 62 | $class = sprintf('Ma27\\ApiKeyAuthenticationBundle\\Annotation\\%s', ucfirst($annotation)); |
||
| 63 | $annotationObject = $this->reader->getPropertyAnnotation($reflectionProperty, $class); |
||
|
|
|||
| 64 | |||
| 65 | if ($annotationObject) { |
||
| 66 | switch ($annotation) { |
||
| 67 | case 'login': |
||
| 68 | if (!empty($loginProperty)) { |
||
| 69 | throw $this->createDuplicateAnnotationException(); |
||
| 70 | } |
||
| 71 | |||
| 72 | $loginProperty = $reflectionProperty; |
||
| 73 | break; |
||
| 74 | case 'password': |
||
| 75 | if (!empty($passwordProperty)) { |
||
| 76 | throw $this->createDuplicateAnnotationException(); |
||
| 77 | } |
||
| 78 | |||
| 79 | $passwordProperty = $reflectionProperty; |
||
| 80 | break; |
||
| 81 | case 'apiKey': |
||
| 82 | if (!empty($apiKeyProperty)) { |
||
| 83 | throw $this->createDuplicateAnnotationException(); |
||
| 84 | } |
||
| 85 | |||
| 86 | $apiKeyProperty = $reflectionProperty; |
||
| 87 | break; |
||
| 88 | case 'lastAction': |
||
| 89 | if (!empty($lastActionProperty)) { |
||
| 90 | throw $this->createDuplicateAnnotationException(); |
||
| 91 | } |
||
| 92 | |||
| 93 | $lastActionProperty = $reflectionProperty; |
||
| 94 | } |
||
| 95 | |||
| 96 | if ($loginProperty |
||
| 97 | && $passwordProperty |
||
| 98 | && $apiKeyProperty |
||
| 99 | && $lastActionProperty |
||
| 100 | ) { |
||
| 101 | break; |
||
| 102 | } |
||
| 103 | |||
| 104 | continue; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 109 | if (!$loginProperty || !$passwordProperty || !$apiKeyProperty) { |
||
| 110 | throw new \LogicException(sprintf( |
||
| 111 | 'A user class must have a "%s", "%s", "%s" annotation!', |
||
| 112 | 'Login', |
||
| 113 | 'Password', |
||
| 114 | 'ApiKey' |
||
| 115 | )); |
||
| 116 | } |
||
| 117 | |||
| 118 | return new ClassMetadata( |
||
| 119 | $reflection, |
||
| 120 | $this->userClass, |
||
| 121 | array( |
||
| 122 | ClassMetadata::LOGIN_PROPERTY => $loginProperty, |
||
| 123 | ClassMetadata::PASSWORD_PROPERTY => $passwordProperty, |
||
| 124 | ClassMetadata::API_KEY_PROPERTY => $apiKeyProperty, |
||
| 125 | ClassMetadata::LAST_ACTION_PROPERTY => $lastActionProperty, |
||
| 126 | ) |
||
| 127 | ); |
||
| 128 | } |
||
| 129 | |||
| 140 |
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.