| Conditions | 13 |
| Paths | 28 |
| Total Lines | 44 |
| Code Lines | 24 |
| Lines | 6 |
| Ratio | 13.64 % |
| 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 |
||
| 32 | public function current() |
||
| 33 | { |
||
| 34 | $data = []; |
||
| 35 | $propertyPaths = $this->propertyPaths; |
||
| 36 | |||
| 37 | // then complete it for "fields" representing a collection of sub-entities |
||
| 38 | foreach ($this->propertyPaths as $i => $propertyPath) { |
||
| 39 | try { |
||
| 40 | if (($property = $this->propertyAccessor->getValue($this->iterator->current()[0], $propertyPath)) instanceof PersistentCollection) { |
||
|
|
|||
| 41 | View Code Duplication | if (!(isset($data[(string) $propertyPath]) && is_array($data[(string) $propertyPath]))) { |
|
| 42 | $data[(string) $propertyPath] = []; |
||
| 43 | } |
||
| 44 | |||
| 45 | foreach ($property as $subEntity) { |
||
| 46 | $data[(string) $propertyPath][] = (string) $subEntity; |
||
| 47 | } |
||
| 48 | |||
| 49 | unset($this->propertyPaths[$i]); |
||
| 50 | } |
||
| 51 | } catch (NoSuchPropertyException $e) { |
||
| 52 | $collection = preg_replace('/\..+$/', '', $propertyPath); |
||
| 53 | $subProperty = preg_replace('/^.+\./U', '', $propertyPath); |
||
| 54 | if ($collection != (string) $propertyPath && $subProperty) { |
||
| 55 | if (($property = $this->propertyAccessor->getValue($this->iterator->current()[0], $collection)) instanceof PersistentCollection) { |
||
| 56 | View Code Duplication | if (!(isset($data[$collection]) && is_array($data[$collection]))) { |
|
| 57 | $data[$collection] = []; |
||
| 58 | } |
||
| 59 | |||
| 60 | foreach ($property as $subEntity) { |
||
| 61 | $data[$collection][spl_object_hash($subEntity)][$subProperty] = (string) $this->propertyAccessor->getValue($subEntity, $subProperty); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | } |
||
| 65 | unset($this->propertyPaths[$i]); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | // first do the "normal" stuff |
||
| 70 | $data = array_merge($data, parent::current()); |
||
| 71 | |||
| 72 | $this->propertyPaths = $propertyPaths; |
||
| 73 | |||
| 74 | return $data; |
||
| 75 | } |
||
| 76 | |||
| 87 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.