Conditions | 8 |
Paths | 56 |
Total Lines | 54 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
89 | public function handlePersist(PersistEvent $event) |
||
90 | { |
||
91 | $options = $event->getOptions(); |
||
92 | $this->validateOptions($options); |
||
|
|||
93 | $document = $event->getDocument(); |
||
94 | $parentPath = null; |
||
95 | $nodeName = null; |
||
96 | |||
97 | if ($options['path']) { |
||
98 | $parentPath = PathHelper::getParentPath($options['path']); |
||
99 | $nodeName = PathHelper::getNodeName($options['path']); |
||
100 | } |
||
101 | |||
102 | if ($options['parent_path']) { |
||
103 | $parentPath = $options['parent_path']; |
||
104 | } |
||
105 | |||
106 | if ($parentPath) { |
||
107 | $event->setParentNode( |
||
108 | $this->resolveParent($parentPath, $options) |
||
109 | ); |
||
110 | } |
||
111 | |||
112 | if ($options['node_name']) { |
||
113 | if (!$event->hasParentNode()) { |
||
114 | throw new DocumentManagerException(sprintf( |
||
115 | 'The "node_name" option can only be used either with the "parent_path" option ' . |
||
116 | 'or when a parent node has been established by a previous subscriber. ' . |
||
117 | 'When persisting document: %s', |
||
118 | DocumentHelper::getDebugTitle($document) |
||
119 | )); |
||
120 | } |
||
121 | |||
122 | $nodeName = $options['node_name']; |
||
123 | } |
||
124 | |||
125 | if (!$nodeName) { |
||
126 | return; |
||
127 | } |
||
128 | |||
129 | if ($event->hasNode()) { |
||
130 | $this->renameNode($event->getNode(), $nodeName); |
||
131 | |||
132 | return; |
||
133 | } |
||
134 | |||
135 | $node = $this->strategy->createNodeForDocument( |
||
136 | $document, |
||
137 | $event->getParentNode(), |
||
138 | $nodeName |
||
139 | ); |
||
140 | |||
141 | $event->setNode($node); |
||
142 | } |
||
143 | |||
179 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: