| Conditions | 2 |
| Paths | 2 |
| Total Lines | 95 |
| Code Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 13 | ||
| 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 | const '.$linkTypeClass.'fx = function() { |
||
| 137 | '.$js.' |
||
| 138 | } |
||
| 139 | jQuery(".'.$linkTypeClass.' input").on("change click", '.$linkTypeClass.'fx()); |
||
| 140 | window.setTimeout( |
||
| 141 | function() { |
||
| 142 | '.$linkTypeClass.'fx(); |
||
| 143 | }, |
||
| 144 | 500 |
||
| 145 | )', |
||
| 146 | $linkTypeClass |
||
| 147 | ); |
||
| 148 | $fields->removeByName([ |
||
| 149 | 'LinkType' . $appendix, |
||
| 150 | 'InternalLink' . $appendix . 'ID', |
||
| 151 | 'DownloadFile' . $appendix, |
||
| 152 | 'ExternalLink' . $appendix, |
||
| 153 | ]); |
||
| 154 | // $fields->insertBefore(new Tab('Links', 'Links'), 'Settings'); |
||
| 155 | $fields->addFieldsToTab( |
||
| 156 | 'Root.Links', |
||
| 157 | [ |
||
| 158 | HeaderField::create( |
||
| 159 | 'Link-Details-Heading' . $appendix, |
||
| 160 | 'Link' |
||
| 161 | ), |
||
| 162 | OptionsetField::create( |
||
| 163 | 'LinkType' . $appendix, |
||
| 164 | 'Link Type ' . $appendix, |
||
| 165 | $this->owner->dbObject('LinkType')->enumValues() |
||
| 166 | ) |
||
| 167 | ->setAttribute('onchange', $js) |
||
| 168 | ->setAttribute('onclick', $js) |
||
| 169 | ->addExtraClass($linkTypeClass), |
||
| 170 | TreeDropdownField::create( |
||
| 171 | 'InternalLink' . $appendix . 'ID', |
||
| 172 | 'Internal Link ' . $appendix, |
||
| 173 | Page::class |
||
| 174 | ) |
||
| 175 | ->addExtraClass($internalClass), |
||
| 176 | TextField::create( |
||
| 177 | 'ExternalLink' . $appendix, |
||
| 178 | 'External Link / Email / Phone' |
||
| 179 | ) |
||
| 180 | ->addExtraClass($externalClass), |
||
| 181 | UploadField::create( |
||
| 182 | 'DownloadFile' . $appendix, |
||
| 183 | 'Download File ' . $appendix |
||
| 184 | ) |
||
| 185 | ->addExtraClass($downloadFileClass), |
||
| 186 | ] |
||
| 187 | ); |
||
| 188 | Requirements::customScript( |
||
| 189 | 'window.setTimeout( |
||
| 190 | function() { |
||
| 191 | jQuery(\'input[name="LinkType' . $appendix . '"]\').change(); |
||
| 192 | } |
||
| 193 | , 500 |
||
| 194 | )', |
||
| 195 | 'InternalExternalLinkKickStart' . $appendix |
||
| 196 | ); |
||
| 230 |
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