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