| Conditions | 12 |
| Paths | 258 |
| Total Lines | 93 |
| Code Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 185 | public function getReportField($itemType = 'Pages') |
||
| 186 | { |
||
| 187 | $params = isset($_REQUEST['filters']) ? $_REQUEST['filters'] : array(); |
||
| 188 | $items = $this->sourceRecords($params, null, null); |
||
| 189 | |||
| 190 | $gridField = new GridFieldBasicContentReport('Report-'.$itemType, false, $items[$itemType]); |
||
| 191 | |||
| 192 | $gridFieldConfig = GridFieldConfig::create()->addComponents( |
||
| 193 | new GridFieldToolbarHeader(), |
||
| 194 | new GridFieldSortableHeader(), |
||
| 195 | new GridFieldDataColumns(), |
||
| 196 | new GridFieldPaginator(), |
||
| 197 | new GridFieldButtonRow('after'), |
||
| 198 | $printButton = new GridFieldPrintButton('buttons-after-left'), |
||
| 199 | $exportButton = new GridFieldExportButton('buttons-after-left') |
||
| 200 | ); |
||
| 201 | |||
| 202 | $gridField->setConfig($gridFieldConfig); |
||
| 203 | |||
| 204 | /* @var $columns GridFieldDataColumns */ |
||
| 205 | $columns = $gridField->getConfig()->getComponentByType(GridFieldDataColumns::class); |
||
| 206 | |||
| 207 | $exportFields = []; |
||
| 208 | $displayFields = []; |
||
| 209 | $fieldCasting = []; |
||
| 210 | $fieldFormatting = []; |
||
| 211 | $dataFields = []; |
||
| 212 | |||
| 213 | // Parse the column information |
||
| 214 | foreach ($this->columns($itemType) as $source => $info) { |
||
| 215 | if (is_string($info)) { |
||
| 216 | $info = ['title' => $info]; |
||
| 217 | } |
||
| 218 | |||
| 219 | if (isset($info['formatting'])) { |
||
| 220 | $fieldFormatting[$source] = $info['formatting']; |
||
| 221 | } |
||
| 222 | if (isset($info['casting'])) { |
||
| 223 | $fieldCasting[$source] = $info['casting']; |
||
| 224 | } |
||
| 225 | |||
| 226 | if (isset($info['link']) && $info['link']) { |
||
| 227 | $fieldFormatting[$source] = function ($value, &$item) { |
||
| 228 | if ($item instanceof Page) { |
||
| 229 | return sprintf( |
||
| 230 | "<a href='%s'>%s</a>", |
||
| 231 | Controller::join_links(singleton(CMSPageEditController::class)->Link('show'), $item->ID), |
||
| 232 | $value |
||
| 233 | ); |
||
| 234 | } |
||
| 235 | |||
| 236 | return sprintf( |
||
| 237 | "<a href='%s'>%s</a>", |
||
| 238 | Controller::join_links( |
||
| 239 | singleton(AssetAdmin::class)->Link('EditForm'), 'field/File/item', $item->ID, 'edit' |
||
| 240 | ), |
||
| 241 | $value |
||
| 242 | ); |
||
| 243 | }; |
||
| 244 | } |
||
| 245 | |||
| 246 | // Set custom datasource |
||
| 247 | if (isset($info['datasource'])) { |
||
| 248 | $dataFields[$source] = $info['datasource']; |
||
| 249 | } |
||
| 250 | |||
| 251 | // Set field name for export |
||
| 252 | $fieldTitle = isset($info['title']) ? $info['title'] : $source; |
||
| 253 | |||
| 254 | // If not print-only, then add to display list |
||
| 255 | if (empty($info['printonly'])) { |
||
| 256 | $displayFields[$source] = $fieldTitle; |
||
| 257 | } |
||
| 258 | |||
| 259 | // Assume that all displayed fields are printed also |
||
| 260 | $exportFields[$source] = $fieldTitle; |
||
| 261 | } |
||
| 262 | |||
| 263 | // Set custom evaluated columns |
||
| 264 | $gridField->addDataFields($dataFields); |
||
| 265 | |||
| 266 | // Set visible fields |
||
| 267 | $columns->setDisplayFields($displayFields); |
||
| 268 | $columns->setFieldCasting($fieldCasting); |
||
| 269 | $columns->setFieldFormatting($fieldFormatting); |
||
| 270 | |||
| 271 | // Get print columns, and merge with print-only columns |
||
| 272 | $printExportColumns = $this->getPrintExportColumns($gridField, $itemType, $exportFields); |
||
| 273 | |||
| 274 | $printButton->setPrintColumns($printExportColumns); |
||
| 275 | $exportButton->setExportColumns($printExportColumns); |
||
| 276 | |||
| 277 | return $gridField; |
||
| 278 | } |
||
| 300 |
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