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