| Conditions | 6 |
| Paths | 1 |
| Total Lines | 78 |
| Code Lines | 49 |
| 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 |
||
| 54 | public function getCMSFields() |
||
| 55 | { |
||
| 56 | $this->beforeUpdateCMSFields(function (FieldList $fields) { |
||
| 57 | $resource = $this->DataResource(); |
||
| 58 | |||
| 59 | $fields->addFieldToTab( |
||
| 60 | 'Root.Data', |
||
| 61 | ResourceLocatorField::create('DataResource') |
||
| 62 | ->addExtraClass('form-field--no-divider') |
||
| 63 | ); |
||
| 64 | |||
| 65 | if ($resource && $resource->Identifier) { |
||
| 66 | $injector = Injector::inst(); |
||
| 67 | |||
| 68 | $columnsConfig = GridFieldConfig_RecordEditor::create() |
||
| 69 | ->addComponents([ |
||
| 70 | $injector->createWithArgs(GridFieldOrderableRows::class, ['Position']), |
||
| 71 | $injector->createWithArgs(GridFieldResourceTitle::class, [$resource]), |
||
| 72 | ]) |
||
| 73 | ->removeComponentsByType([ |
||
| 74 | GridFieldAddNewButton::class, |
||
| 75 | GridFieldDeleteAction::class, |
||
| 76 | GridFieldPageCount::class, |
||
| 77 | GridFieldToolbarHeader::class, |
||
| 78 | ]); |
||
| 79 | |||
| 80 | $columnsConfig->getComponentByType(GridFieldDetailForm::class) |
||
| 81 | ->setItemRequestClass(ResourceFieldItemRequest::class); |
||
| 82 | |||
| 83 | $resourceFields = GridField::create('DataColumns', '', $resource->Fields(), $columnsConfig); |
||
| 84 | $resourceFields->addExtraClass('ckan-columns'); |
||
| 85 | |||
| 86 | // Configure inline editable checkboxes for the two boolean fields |
||
| 87 | $before = null; |
||
| 88 | $editableColumns = $injector->create(GridFieldEditableColumns::class); |
||
| 89 | foreach ($columnsConfig->getComponents() as $component) { |
||
| 90 | if ($before !== null) { |
||
| 91 | $before = $component; |
||
| 92 | break; |
||
| 93 | } |
||
| 94 | if ($component instanceof GridFieldDataColumns) { |
||
| 95 | $before = false; |
||
| 96 | $columns = $component->getDisplayFields($resourceFields); |
||
| 97 | |||
| 98 | // We only want to change the labels for the GridField view, not the model's edit form |
||
| 99 | $columns['ShowInResultsView'] = _t(__CLASS__ . '.IN_RESULTS', 'In Results'); |
||
| 100 | $columns['ShowInDetailView'] = _t(__CLASS__ . '.IN_DETAIL', 'In Detail'); |
||
| 101 | |||
| 102 | // Abbreviate the position title |
||
| 103 | $columns['Position'] = _t(__CLASS__ . '.POS', 'Pos.', 'Abbreviated version of position'); |
||
| 104 | |||
| 105 | $editable = array_flip(['ShowInResultsView', 'ShowInDetailView']); |
||
| 106 | $component->setDisplayFields(array_diff_key($columns, $editable)); |
||
| 107 | // set this way so that title translations are preserved |
||
| 108 | $editableColumns->setDisplayFields(array_intersect_key($columns, $editable)); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | $columnsConfig->addComponent($editableColumns, $before); |
||
| 112 | $fields->addFieldToTab('Root.Data', $resourceFields); |
||
| 113 | |||
| 114 | $filtersConfig = GridFieldConfig_RecordEditor::create(); |
||
| 115 | $filtersConfig |
||
| 116 | ->removeComponentsByType([ |
||
| 117 | GridFieldAddExistingAutocompleter::class, |
||
| 118 | GridFieldAddNewButton::class |
||
| 119 | ]) |
||
| 120 | ->addComponents([ |
||
| 121 | $injector->create(GridFieldAddNewMultiClass::class), |
||
| 122 | $injector->createWithArgs(GridFieldOrderableRows::class, ['Order']), |
||
| 123 | ]); |
||
| 124 | |||
| 125 | $resourceFilters = GridField::create('DataFilters', '', $resource->Filters(), $filtersConfig); |
||
| 126 | |||
| 127 | $fields->addFieldToTab('Root.Filters', $resourceFilters); |
||
| 128 | } |
||
| 129 | }); |
||
| 130 | |||
| 131 | return parent::getCMSFields(); |
||
| 132 | } |
||
| 150 |
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