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