| Conditions | 33 |
| Paths | 16 |
| Total Lines | 116 |
| Code Lines | 69 |
| Lines | 49 |
| Ratio | 42.24 % |
| 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 |
||
| 59 | public function convertDataObjectWithoutHeader(DataObject $obj, $fields = null, $relations = null) |
||
| 60 | { |
||
| 61 | $className = $this->sanitiseClassName(get_class($obj)); |
||
| 62 | $id = $obj->ID; |
||
| 63 | $objHref = Director::absoluteURL($this->config()->api_base . "$className/$obj->ID"); |
||
| 64 | |||
| 65 | $xml = "<$className href=\"$objHref.xml\">\n"; |
||
| 66 | foreach ($this->getFieldsForObj($obj) as $fieldName => $fieldType) { |
||
| 67 | // Field filtering |
||
| 68 | if ($fields && !in_array($fieldName, $fields)) { |
||
| 69 | continue; |
||
| 70 | } |
||
| 71 | $fieldValue = $obj->obj($fieldName)->forTemplate(); |
||
| 72 | if (!mb_check_encoding($fieldValue, 'utf-8')) { |
||
| 73 | $fieldValue = "(data is badly encoded)"; |
||
| 74 | } |
||
| 75 | |||
| 76 | if (is_object($fieldValue) && is_subclass_of($fieldValue, 'Object') && $fieldValue->hasMethod('toXML')) { |
||
| 77 | $xml .= $fieldValue->toXML(); |
||
| 78 | } else { |
||
| 79 | if ('HTMLText' == $fieldType) { |
||
| 80 | // Escape HTML values using CDATA |
||
| 81 | $fieldValue = sprintf('<![CDATA[%s]]>', str_replace(']]>', ']]]]><![CDATA[>', $fieldValue)); |
||
| 82 | } else { |
||
| 83 | $fieldValue = Convert::raw2xml($fieldValue); |
||
| 84 | } |
||
| 85 | $xml .= "<$fieldName>$fieldValue</$fieldName>\n"; |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | if ($this->relationDepth > 0) { |
||
| 90 | foreach ($obj->hasOne() as $relName => $relClass) { |
||
| 91 | if (!singleton($relClass)->stat('api_access')) { |
||
| 92 | continue; |
||
| 93 | } |
||
| 94 | |||
| 95 | // Field filtering |
||
| 96 | if ($fields && !in_array($relName, $fields)) { |
||
| 97 | continue; |
||
| 98 | } |
||
| 99 | if ($this->customRelations && !in_array($relName, $this->customRelations)) { |
||
| 100 | continue; |
||
| 101 | } |
||
| 102 | |||
| 103 | $fieldName = $relName . 'ID'; |
||
| 104 | View Code Duplication | if ($obj->$fieldName) { |
|
| 105 | $href = Director::absoluteURL($this->config()->api_base . "$relClass/" . $obj->$fieldName); |
||
| 106 | } else { |
||
| 107 | $href = Director::absoluteURL($this->config()->api_base . "$className/$id/$relName"); |
||
| 108 | } |
||
| 109 | $xml .= "<$relName linktype=\"has_one\" href=\"$href.xml\" id=\"" . $obj->$fieldName |
||
| 110 | . "\"></$relName>\n"; |
||
| 111 | } |
||
| 112 | |||
| 113 | View Code Duplication | foreach ($obj->hasMany() as $relName => $relClass) { |
|
| 114 | //remove dot notation from relation names |
||
| 115 | $parts = explode('.', $relClass); |
||
| 116 | $relClass = array_shift($parts); |
||
| 117 | if (!singleton($relClass)->stat('api_access')) { |
||
| 118 | continue; |
||
| 119 | } |
||
| 120 | // backslashes in FQCNs kills both URIs and XML |
||
| 121 | $relClass = $this->sanitiseClassName($relClass); |
||
| 122 | |||
| 123 | // Field filtering |
||
| 124 | if ($fields && !in_array($relName, $fields)) { |
||
| 125 | continue; |
||
| 126 | } |
||
| 127 | if ($this->customRelations && !in_array($relName, $this->customRelations)) { |
||
| 128 | continue; |
||
| 129 | } |
||
| 130 | |||
| 131 | $xml .= "<$relName linktype=\"has_many\" href=\"$objHref/$relName.xml\">\n"; |
||
| 132 | $items = $obj->$relName(); |
||
| 133 | if ($items) { |
||
| 134 | foreach ($items as $item) { |
||
| 135 | $href = Director::absoluteURL($this->config()->api_base . "$relClass/$item->ID"); |
||
| 136 | $xml .= "<$relClass href=\"$href.xml\" id=\"{$item->ID}\"></$relClass>\n"; |
||
| 137 | } |
||
| 138 | } |
||
| 139 | $xml .= "</$relName>\n"; |
||
| 140 | } |
||
| 141 | |||
| 142 | View Code Duplication | foreach ($obj->manyMany() as $relName => $relClass) { |
|
| 143 | //remove dot notation from relation names |
||
| 144 | $parts = explode('.', $relClass); |
||
| 145 | $relClass = array_shift($parts); |
||
| 146 | if (!singleton($relClass)->stat('api_access')) { |
||
| 147 | continue; |
||
| 148 | } |
||
| 149 | // backslashes in FQCNs kills both URIs and XML |
||
| 150 | $relClass = $this->sanitiseClassName($relClass); |
||
| 151 | |||
| 152 | // Field filtering |
||
| 153 | if ($fields && !in_array($relName, $fields)) { |
||
| 154 | continue; |
||
| 155 | } |
||
| 156 | if ($this->customRelations && !in_array($relName, $this->customRelations)) { |
||
| 157 | continue; |
||
| 158 | } |
||
| 159 | |||
| 160 | $xml .= "<$relName linktype=\"many_many\" href=\"$objHref/$relName.xml\">\n"; |
||
| 161 | $items = $obj->$relName(); |
||
| 162 | if ($items) { |
||
| 163 | foreach ($items as $item) { |
||
| 164 | $href = Director::absoluteURL($this->config()->api_base . "$relClass/$item->ID"); |
||
| 165 | $xml .= "<$relClass href=\"$href.xml\" id=\"{$item->ID}\"></$relClass>\n"; |
||
| 166 | } |
||
| 167 | } |
||
| 168 | $xml .= "</$relName>\n"; |
||
| 169 | } |
||
| 170 | } |
||
| 171 | |||
| 172 | $xml .= "</$className>"; |
||
| 173 | |||
| 174 | return $xml; |
||
| 175 | } |
||
| 203 |
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