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 |
||
33 | public function current() |
||
34 | { |
||
35 | $data = []; |
||
36 | $propertyPaths = $this->propertyPaths; |
||
37 | |||
38 | // then complete it for "fields" representing a collection of sub-entities |
||
39 | foreach ($this->propertyPaths as $i => $propertyPath) { |
||
40 | try { |
||
41 | if (($property = $this->propertyAccessor->getValue($this->iterator->current()[0], $propertyPath)) instanceof PersistentCollection) { |
||
|
|||
42 | View Code Duplication | if (!(isset($data[(string) $propertyPath]) && is_array($data[(string) $propertyPath]))) { |
|
43 | $data[(string) $propertyPath] = []; |
||
44 | } |
||
45 | |||
46 | foreach ($property as $subEntity) { |
||
47 | $data[(string) $propertyPath][] = (string) $subEntity; |
||
48 | } |
||
49 | |||
50 | unset($this->propertyPaths[$i]); |
||
51 | } |
||
52 | } catch (NoSuchPropertyException $e) { |
||
53 | $collection = preg_replace('/\..+$/', '', $propertyPath); |
||
54 | $subProperty = preg_replace('/^.+\./U', '', $propertyPath); |
||
55 | if ($collection != (string) $propertyPath && $subProperty) { |
||
56 | if (($property = $this->propertyAccessor->getValue($this->iterator->current()[0], $collection)) instanceof PersistentCollection) { |
||
57 | View Code Duplication | if (!(isset($data[$collection]) && is_array($data[$collection]))) { |
|
58 | $data[$collection] = []; |
||
59 | } |
||
60 | |||
61 | foreach ($property as $subEntity) { |
||
62 | $data[$collection][spl_object_hash($subEntity)][$subProperty] = (string) $this->propertyAccessor->getValue($subEntity, $subProperty); |
||
63 | } |
||
64 | } |
||
65 | } |
||
66 | unset($this->propertyPaths[$i]); |
||
67 | } |
||
68 | } |
||
69 | |||
70 | // first do the "normal" stuff |
||
71 | $data = array_merge($data, parent::current()); |
||
72 | |||
73 | $this->propertyPaths = $propertyPaths; |
||
74 | |||
75 | return $data; |
||
76 | } |
||
77 | |||
88 |
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.