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