Conditions | 2 |
Paths | 2 |
Total Lines | 100 |
Code Lines | 55 |
Lines | 0 |
Ratio | 0 % |
Changes | 16 | ||
Bugs | 0 | Features | 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 |
||
98 | public function updateCMSFields(FieldList $fields) |
||
99 | { |
||
100 | $fieldNameAppendici = $this->getFieldNameAppendici(); |
||
101 | foreach ($fieldNameAppendici as $appendix) { |
||
102 | $linkTypeClass = 'LinkType' . $appendix . '_' . rand(0, 999999); |
||
103 | $internalClass = 'InternalLink' . $appendix . 'ID_' . rand(0, 999999); |
||
104 | $externalClass = 'ExternalLink' . $appendix . '_' . rand(0, 999999); |
||
105 | $downloadFileClass = 'DownloadFile' . $appendix . '_' . rand(0, 999999); |
||
106 | |||
107 | $js = <<<js |
||
108 | var el = this; |
||
109 | const val = jQuery('.{$linkTypeClass}').find('.form-check-input:checked').val(); |
||
110 | const internaLinkHolder = jQuery('.{$internalClass}'); |
||
111 | const externaLinkHolder = jQuery('.{$externalClass}'); |
||
112 | const downloadLinkHolder = jQuery('.{$downloadFileClass}'); |
||
113 | if (val === 'Internal') { |
||
114 | internaLinkHolder.show(); |
||
115 | externaLinkHolder.hide(); |
||
116 | downloadLinkHolder.hide(); |
||
117 | } else if(val === 'External' || val === 'Phone' || val === 'Email') { |
||
118 | internaLinkHolder.hide(); |
||
119 | externaLinkHolder.show(); |
||
120 | downloadLinkHolder.hide(); |
||
121 | } else if(val === 'DownloadFile') { |
||
122 | internaLinkHolder.hide(); |
||
123 | externaLinkHolder.hide(); |
||
124 | downloadLinkHolder.show(); |
||
125 | } else { |
||
126 | internaLinkHolder.show(); |
||
127 | externaLinkHolder.show(); |
||
128 | downloadLinkHolder.show(); |
||
129 | } |
||
130 | |||
131 | js; |
||
132 | Requirements::customScript( |
||
133 | ' |
||
134 | const ' . $linkTypeClass . 'fx = function() { |
||
135 | ' . $js . ' |
||
136 | } |
||
137 | jQuery(".' . $linkTypeClass . ' input").on("change click", ' . $linkTypeClass . 'fx()); |
||
138 | window.setInterval( |
||
139 | function() { |
||
140 | ' . $linkTypeClass . 'fx(); |
||
141 | }, |
||
142 | 700 |
||
143 | )', |
||
144 | $linkTypeClass |
||
145 | ); |
||
146 | $fields->removeByName([ |
||
147 | 'LinkType' . $appendix, |
||
148 | 'InternalLink' . $appendix . 'ID', |
||
149 | 'DownloadFile' . $appendix, |
||
150 | 'ExternalLink' . $appendix, |
||
151 | ]); |
||
152 | // $fields->insertBefore(new Tab('Links', 'Links'), 'Settings'); |
||
153 | $fields->addFieldsToTab( |
||
154 | 'Root.Links', |
||
155 | [ |
||
156 | HeaderField::create( |
||
157 | 'Link-Details-Heading' . $appendix, |
||
158 | 'Link' |
||
159 | ), |
||
160 | |||
161 | OptionsetField::create( |
||
162 | 'LinkType' . $appendix, |
||
163 | 'Link Type ' . $appendix, |
||
164 | $this->owner->dbObject('LinkType')->enumValues() |
||
165 | ) |
||
166 | ->setAttribute('onchange', $js) |
||
167 | ->setAttribute('onclick', $js) |
||
168 | ->addExtraClass($linkTypeClass), |
||
169 | |||
170 | TreeDropdownField::create( |
||
171 | 'InternalLink' . $appendix . 'ID', |
||
172 | 'Internal Link ' . $appendix, |
||
173 | Page::class |
||
174 | ) |
||
175 | ->addExtraClass($internalClass), |
||
176 | |||
177 | TextField::create( |
||
178 | 'ExternalLink' . $appendix, |
||
179 | 'External Link / Email / Phone' |
||
180 | ) |
||
181 | ->addExtraClass($externalClass), |
||
182 | |||
183 | UploadField::create( |
||
184 | 'DownloadFile' . $appendix, |
||
185 | 'Download File ' . $appendix |
||
186 | ) |
||
187 | ->addExtraClass($downloadFileClass), |
||
188 | ] |
||
189 | ); |
||
190 | Requirements::customScript( |
||
191 | 'window.setTimeout( |
||
192 | function() { |
||
193 | jQuery(\'input[name="LinkType' . $appendix . '"]\').change(); |
||
194 | } |
||
195 | , 500 |
||
196 | )', |
||
197 | 'InternalExternalLinkKickStart' . $appendix |
||
198 | ); |
||
214 |
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