Conditions | 33 |
Paths | 16 |
Total Lines | 116 |
Code Lines | 69 |
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 |
||
114 | public function convertDataObjectWithoutHeader(DataObject $obj, $fields = null, $relations = null) |
||
115 | { |
||
116 | $className = $this->sanitiseClassName(get_class($obj)); |
||
117 | $id = $obj->ID; |
||
118 | $objHref = Director::absoluteURL($this->config()->api_base . "$className/$obj->ID"); |
||
119 | |||
120 | $xml = "<$className href=\"$objHref.xml\">\n"; |
||
121 | foreach ($this->getFieldsForObj($obj) as $fieldName => $fieldType) { |
||
122 | // Field filtering |
||
123 | if ($fields && !in_array($fieldName, $fields)) { |
||
124 | continue; |
||
125 | } |
||
126 | $fieldValue = $obj->obj($fieldName)->forTemplate(); |
||
127 | if (!mb_check_encoding($fieldValue, 'utf-8')) { |
||
128 | $fieldValue = "(data is badly encoded)"; |
||
129 | } |
||
130 | |||
131 | if (is_object($fieldValue) && is_subclass_of($fieldValue, 'Object') && $fieldValue->hasMethod('toXML')) { |
||
132 | $xml .= $fieldValue->toXML(); |
||
133 | } else { |
||
134 | if ('HTMLText' == $fieldType) { |
||
135 | // Escape HTML values using CDATA |
||
136 | $fieldValue = sprintf('<![CDATA[%s]]>', str_replace(']]>', ']]]]><![CDATA[>', $fieldValue)); |
||
137 | } else { |
||
138 | $fieldValue = Convert::raw2xml($fieldValue); |
||
139 | } |
||
140 | $xml .= "<$fieldName>$fieldValue</$fieldName>\n"; |
||
141 | } |
||
142 | } |
||
143 | |||
144 | if ($this->relationDepth > 0) { |
||
145 | foreach ($obj->hasOne() as $relName => $relClass) { |
||
146 | if (!singleton($relClass)->stat('api_access')) { |
||
147 | continue; |
||
148 | } |
||
149 | |||
150 | // Field filtering |
||
151 | if ($fields && !in_array($relName, $fields)) { |
||
152 | continue; |
||
153 | } |
||
154 | if ($this->customRelations && !in_array($relName, $this->customRelations)) { |
||
155 | continue; |
||
156 | } |
||
157 | |||
158 | $fieldName = $relName . 'ID'; |
||
159 | if ($obj->$fieldName) { |
||
160 | $href = Director::absoluteURL($this->config()->api_base . "$relClass/" . $obj->$fieldName); |
||
161 | } else { |
||
162 | $href = Director::absoluteURL($this->config()->api_base . "$className/$id/$relName"); |
||
163 | } |
||
164 | $xml .= "<$relName linktype=\"has_one\" href=\"$href.xml\" id=\"" . $obj->$fieldName |
||
165 | . "\"></$relName>\n"; |
||
166 | } |
||
167 | |||
168 | foreach ($obj->hasMany() as $relName => $relClass) { |
||
169 | //remove dot notation from relation names |
||
170 | $parts = explode('.', $relClass); |
||
171 | $relClass = array_shift($parts); |
||
172 | if (!singleton($relClass)->stat('api_access')) { |
||
173 | continue; |
||
174 | } |
||
175 | // backslashes in FQCNs kills both URIs and XML |
||
176 | $relClass = $this->sanitiseClassName($relClass); |
||
177 | |||
178 | // Field filtering |
||
179 | if ($fields && !in_array($relName, $fields)) { |
||
180 | continue; |
||
181 | } |
||
182 | if ($this->customRelations && !in_array($relName, $this->customRelations)) { |
||
183 | continue; |
||
184 | } |
||
185 | |||
186 | $xml .= "<$relName linktype=\"has_many\" href=\"$objHref/$relName.xml\">\n"; |
||
187 | $items = $obj->$relName(); |
||
188 | if ($items) { |
||
189 | foreach ($items as $item) { |
||
190 | $href = Director::absoluteURL($this->config()->api_base . "$relClass/$item->ID"); |
||
191 | $xml .= "<$relClass href=\"$href.xml\" id=\"{$item->ID}\"></$relClass>\n"; |
||
192 | } |
||
193 | } |
||
194 | $xml .= "</$relName>\n"; |
||
195 | } |
||
196 | |||
197 | foreach ($obj->manyMany() as $relName => $relClass) { |
||
198 | //remove dot notation from relation names |
||
199 | $parts = explode('.', $relClass); |
||
200 | $relClass = array_shift($parts); |
||
201 | if (!singleton($relClass)->stat('api_access')) { |
||
202 | continue; |
||
203 | } |
||
204 | // backslashes in FQCNs kills both URIs and XML |
||
205 | $relClass = $this->sanitiseClassName($relClass); |
||
206 | |||
207 | // Field filtering |
||
208 | if ($fields && !in_array($relName, $fields)) { |
||
209 | continue; |
||
210 | } |
||
211 | if ($this->customRelations && !in_array($relName, $this->customRelations)) { |
||
212 | continue; |
||
213 | } |
||
214 | |||
215 | $xml .= "<$relName linktype=\"many_many\" href=\"$objHref/$relName.xml\">\n"; |
||
216 | $items = $obj->$relName(); |
||
217 | if ($items) { |
||
218 | foreach ($items as $item) { |
||
219 | $href = Director::absoluteURL($this->config()->api_base . "$relClass/$item->ID"); |
||
220 | $xml .= "<$relClass href=\"$href.xml\" id=\"{$item->ID}\"></$relClass>\n"; |
||
221 | } |
||
222 | } |
||
223 | $xml .= "</$relName>\n"; |
||
224 | } |
||
225 | } |
||
226 | |||
227 | $xml .= "</$className>"; |
||
228 | |||
229 | return $xml; |
||
230 | } |
||
263 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths