Conditions | 16 |
Paths | 41 |
Total Lines | 56 |
Code Lines | 38 |
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 |
||
156 | protected function loadReceiverProperties(\ReflectionClass $class) |
||
157 | { |
||
158 | $receiverPropertiesTypes = []; |
||
159 | $properties = $class->getProperties(); |
||
160 | //Store receiver properties |
||
161 | foreach ($properties as $property) { |
||
162 | $annotations = $this->reader->getPropertyAnnotations($property); |
||
163 | foreach ($annotations as $key => $annotationObj) { |
||
164 | if ($annotationObj instanceof ReceiverPropertyAnnotation && !in_array($class, $receiverPropertiesTypes)) { |
||
165 | if (!$annotations[$key]->getTypes()) { |
||
166 | $message = $class->name.':$'.$property->name.'" field'; |
||
167 | throw AnnotationException::requiredError('type', 'ReceiverProperty annotation', $message, 'array or string'); |
||
168 | } |
||
169 | foreach ($annotations[$key]->getTypes() as $type) { |
||
170 | $receiverProperty = new ReceiverProperty(); |
||
171 | $receiverProperty->setFieldName($property->name); |
||
172 | $receiverPropertiesTypes[$type][] = $receiverProperty; |
||
173 | } |
||
174 | } |
||
175 | } |
||
176 | } |
||
177 | //Set receiver properties as required if necessary |
||
178 | foreach ($receiverPropertiesTypes as $type => $receiverProperties) { |
||
179 | /* @var ReceiverProperty[] $receiverProperties */ |
||
180 | foreach ($receiverProperties as $receiverProperty) { |
||
181 | $receiverPropertyName = $receiverProperty->getFieldName(); |
||
182 | $refProperty = $class->getProperty($receiverPropertyName); |
||
183 | $annotations = $this->reader->getPropertyAnnotations($refProperty); |
||
184 | foreach ($annotations as $key => $annotationObj) { |
||
185 | if ($annotationObj instanceof Column && $annotationObj->nullable === false) { |
||
186 | throw new Exception(sprintf( |
||
187 | 'Property "%s" in class "%s" has a @ReceiverProperty annotation and by consequence must have "nullable=true" for ORM\Column annotation', |
||
188 | $refProperty->name, |
||
189 | $refProperty->class |
||
190 | )); |
||
191 | } elseif ($annotationObj instanceof NotBlank) { |
||
192 | throw new Exception(sprintf( |
||
193 | 'Property "%s" in class "%s" has a @ReceiverProperty annotation and by consequence can not use NotBlank annotation', |
||
194 | $refProperty->name, |
||
195 | $refProperty->class |
||
196 | )); |
||
197 | } elseif ($annotationObj instanceof NotNull) { |
||
198 | throw new Exception(sprintf( |
||
199 | 'Property "%s" in class "%s" has a @ReceiverProperty annotation and by consequence can not use NotNull annotation', |
||
200 | $refProperty->name, |
||
201 | $refProperty->class |
||
202 | )); |
||
203 | } elseif ($annotationObj instanceof ReceiverPropertyAnnotation && $annotationObj->isRequired()) { |
||
204 | $receiverProperty->setRequired(true); |
||
205 | } |
||
206 | } |
||
207 | } |
||
208 | } |
||
209 | |||
210 | return $receiverPropertiesTypes; |
||
211 | } |
||
212 | } |
||
213 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.