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