| Conditions | 23 |
| Paths | 6 |
| Total Lines | 86 |
| Code Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 80 | public function convertDataObjectToJSONObject(DataObjectInterface $obj, $fields = null, $relations = null) |
||
| 81 | { |
||
| 82 | $className = get_class($obj); |
||
| 83 | $id = $obj->ID; |
||
| 84 | |||
| 85 | $serobj = ArrayData::array_to_object(); |
||
| 86 | |||
| 87 | foreach ($this->getFieldsForObj($obj) as $fieldName => $fieldType) { |
||
| 88 | // Field filtering |
||
| 89 | if ($fields && !in_array($fieldName, $fields)) { |
||
| 90 | continue; |
||
| 91 | } |
||
| 92 | |||
| 93 | $fieldValue = self::cast($obj->obj($fieldName)); |
||
| 94 | $mappedFieldName = $this->getFieldAlias($className, $fieldName); |
||
| 95 | $serobj->$mappedFieldName = $fieldValue; |
||
| 96 | } |
||
| 97 | |||
| 98 | if ($this->relationDepth > 0) { |
||
| 99 | foreach ($obj->hasOne() as $relName => $relClass) { |
||
| 100 | if (!singleton($relClass)->stat('api_access')) { |
||
| 101 | continue; |
||
| 102 | } |
||
| 103 | |||
| 104 | // Field filtering |
||
| 105 | if ($fields && !in_array($relName, $fields)) { |
||
| 106 | continue; |
||
| 107 | } |
||
| 108 | if ($this->customRelations && !in_array($relName, $this->customRelations)) { |
||
| 109 | continue; |
||
| 110 | } |
||
| 111 | if ($obj->$relName() && (!$obj->$relName()->exists() || !$obj->$relName()->canView())) { |
||
| 112 | continue; |
||
| 113 | } |
||
| 114 | |||
| 115 | $fieldName = $relName . 'ID'; |
||
| 116 | $rel = $this->config()->api_base; |
||
| 117 | $rel .= $obj->$fieldName |
||
| 118 | ? $this->sanitiseClassName($relClass) . '/' . $obj->$fieldName |
||
| 119 | : $this->sanitiseClassName($className) . "/$id/$relName"; |
||
| 120 | $href = Director::absoluteURL($rel); |
||
| 121 | $serobj->$relName = ArrayData::array_to_object(array( |
||
| 122 | "className" => $relClass, |
||
| 123 | "href" => "$href.json", |
||
| 124 | "id" => self::cast($obj->obj($fieldName)) |
||
| 125 | )); |
||
| 126 | } |
||
| 127 | |||
| 128 | foreach ($obj->hasMany() + $obj->manyMany() as $relName => $relClass) { |
||
| 129 | $relClass = RestfulServer::parseRelationClass($relClass); |
||
| 130 | |||
| 131 | //remove dot notation from relation names |
||
| 132 | $parts = explode('.', $relClass); |
||
| 133 | $relClass = array_shift($parts); |
||
| 134 | |||
| 135 | if (!singleton($relClass)->stat('api_access')) { |
||
| 136 | continue; |
||
| 137 | } |
||
| 138 | |||
| 139 | // Field filtering |
||
| 140 | if ($fields && !in_array($relName, $fields)) { |
||
| 141 | continue; |
||
| 142 | } |
||
| 143 | if ($this->customRelations && !in_array($relName, $this->customRelations)) { |
||
| 144 | continue; |
||
| 145 | } |
||
| 146 | |||
| 147 | $innerParts = array(); |
||
| 148 | $items = $obj->$relName(); |
||
| 149 | foreach ($items as $item) { |
||
| 150 | if (!$item->canView()) { |
||
| 151 | continue; |
||
| 152 | } |
||
| 153 | $rel = $this->config()->api_base . $this->sanitiseClassName($relClass) . "/$item->ID"; |
||
| 154 | $href = Director::absoluteURL($rel); |
||
| 155 | $innerParts[] = ArrayData::array_to_object(array( |
||
| 156 | "className" => $relClass, |
||
| 157 | "href" => "$href.json", |
||
| 158 | "id" => $item->ID |
||
| 159 | )); |
||
| 160 | } |
||
| 161 | $serobj->$relName = $innerParts; |
||
| 162 | } |
||
| 163 | } |
||
| 164 | |||
| 165 | return $serobj; |
||
| 166 | } |
||
| 216 |
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