Conditions | 12 |
Paths | 76 |
Total Lines | 59 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
49 | public function handle(GridField $gridField, Controller $controller, $arguments = [], $data = []) |
||
50 | { |
||
51 | $fieldName = $gridField->getName(); |
||
52 | $list = $gridField->getList(); |
||
53 | $model = $gridField->getModelClass(); |
||
54 | |||
55 | // Without this, handleSave does not work |
||
56 | $gridField->setSubmittedValue($data[$fieldName]); |
||
57 | |||
58 | if (!($list instanceof DataList)) { |
||
59 | throw new Exception("Requires a DataList"); |
||
60 | } |
||
61 | |||
62 | $updatedData = $data[$fieldName]['GridFieldEditableColumns'] ?? []; |
||
63 | foreach ($updatedData as $id => $values) { |
||
64 | $record = $list->byID($id); |
||
65 | if (!$record) { |
||
66 | continue; |
||
67 | } |
||
68 | // You can use the grid field component or a simple loop with write |
||
69 | if ($this->useHandleSave) { |
||
70 | /** @var GridFieldEditableColumns $component */ |
||
71 | $component = $gridField->getConfig()->getComponentByType(GridFieldEditableColumns::class); |
||
72 | $component->handleSave($gridField, $record); |
||
73 | } else { |
||
74 | foreach ($values as $k => $v) { |
||
75 | $record->$k = $v; |
||
76 | } |
||
77 | $record->write(); |
||
78 | } |
||
79 | } |
||
80 | $newData = $data[$fieldName]['GridFieldAddNewInlineButton'] ?? []; |
||
81 | foreach ($newData as $idx => $values) { |
||
82 | $record = new $model; |
||
83 | if ($this->useHandleSave) { |
||
84 | /** @var GridFieldAddNewInlineButton $component */ |
||
85 | $component = $gridField->getConfig()->getComponentByType(GridFieldAddNewInlineButton::class); |
||
86 | $component->handleSave($gridField, $record); |
||
87 | } else { |
||
88 | foreach ($values as $k => $v) { |
||
89 | $record->$k = $v; |
||
90 | } |
||
91 | } |
||
92 | $record->write(); |
||
93 | } |
||
94 | |||
95 | $response = $controller->getResponse(); |
||
96 | |||
97 | if (Director::is_ajax()) { |
||
98 | if (!$this->completeMessage) { |
||
99 | $this->completeMessage = _t('GridFieldSaveAllButton.DONE', 'All saved'); |
||
100 | } |
||
101 | if ($this->shouldReload) { |
||
102 | ActionsGridFieldItemRequest::addXReload($controller); |
||
103 | } |
||
104 | $response->addHeader('X-Status', rawurlencode($this->completeMessage)); |
||
105 | return null; |
||
106 | } else { |
||
107 | return $controller->redirectBack(); |
||
108 | } |
||
168 |
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