Conditions | 12 |
Paths | 4 |
Total Lines | 57 |
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 |
||
128 | public static function entryToXML($entry, $entrySectionHandle, $includedElements, $entryFields, $position = 0) { |
||
129 | $entryData = $entry->getData(); |
||
130 | $entryId = General::intval($entry->get('id')); |
||
131 | $xml = new XMLElement('entry'); |
||
132 | $xml->setAttribute('id', $entryId); |
||
133 | $xml->setAttribute('section-id', $entry->get('section_id')); |
||
134 | $xml->setAttribute('section', $entrySectionHandle); |
||
135 | if ($position) { |
||
136 | $xml->setAttribute('position', (string)$position); |
||
137 | } |
||
138 | if (!empty($entryData)) { |
||
139 | foreach ($entryData as $fieldId => $data) { |
||
140 | $filteredData = array_filter($data, function ($value) { |
||
141 | return $value != null; |
||
142 | }); |
||
143 | if (empty($filteredData)) { |
||
144 | continue; |
||
145 | } |
||
146 | $field = $entryFields[$fieldId]; |
||
147 | $fieldName = $field->get('element_name'); |
||
148 | $fieldIncludedElement = $includedElements[$entrySectionHandle]; |
||
149 | |||
150 | try { |
||
151 | if (FieldEntry_relationship::isFieldIncluded($fieldName, $fieldIncludedElement)) { |
||
152 | $submodes = FieldEntry_relationship::getAllSelectedFieldModes($fieldName, $fieldIncludedElement); |
||
153 | |||
154 | // Special treatments for ERF |
||
155 | if ($field instanceof FieldEntry_relationship) { |
||
156 | // Increment recursive level |
||
157 | $field->incrementRecursiveLevel(); |
||
158 | $field->setRecursiveDeepness($deepness); |
||
|
|||
159 | } |
||
160 | |||
161 | if ($submodes == null) { |
||
162 | if ($field instanceof FieldEntry_Relationship) { |
||
163 | $field->expandIncludableElements = false; |
||
164 | } |
||
165 | $submodes = array_map(function ($fieldIncludableElement) use ($fieldName) { |
||
166 | return FieldEntry_relationship::extractMode($fieldName, $fieldIncludableElement); |
||
167 | }, $field->fetchIncludableElements()); |
||
168 | if ($field instanceof FieldEntry_Relationship) { |
||
169 | $field->expandIncludableElements = true; |
||
170 | } |
||
171 | } |
||
172 | |||
173 | foreach ($submodes as $submode) { |
||
174 | $field->appendFormattedElement($xml, $filteredData, false, $submode, $entryId); |
||
175 | } |
||
176 | } |
||
177 | } |
||
178 | catch (Exception $ex) { |
||
179 | $xml->appendChild(new XMLElement('error', $ex->getMessage() . ' on ' . $ex->getLine() . ' of file ' . $ex->getFile())); |
||
180 | } |
||
181 | } |
||
182 | } |
||
183 | return $xml; |
||
184 | } |
||
185 | } |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.