Conditions | 11 |
Paths | 100 |
Total Lines | 56 |
Code Lines | 36 |
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 |
||
34 | public function handle(GridField $gridField, Controller $controller, $arguments = [], $data = []) |
||
35 | { |
||
36 | $fieldName = $gridField->getName(); |
||
37 | $list = $gridField->getList(); |
||
38 | $model = $gridField->getModelClass(); |
||
39 | |||
40 | // Without this, handleSave does not work |
||
41 | $gridField->setSubmittedValue($data[$fieldName]); |
||
42 | |||
43 | $updatedData = $data[$fieldName]['GridFieldEditableColumns'] ?? []; |
||
44 | foreach ($updatedData as $id => $values) { |
||
45 | /** @var DataObject $record */ |
||
46 | $record = $list->byID($id); |
||
47 | if (!$record) { |
||
48 | continue; |
||
49 | } |
||
50 | // You can use the grid field component or a simple loop with write |
||
51 | if ($this->useHandleSave) { |
||
52 | /** @var \Symbiote\GridFieldExtensions\GridFieldEditableColumns $component */ |
||
53 | $component = $gridField->getConfig()->getComponentByType(\Symbiote\GridFieldExtensions\GridFieldEditableColumns::class); |
||
|
|||
54 | $component->handleSave($gridField, $record); |
||
55 | } else { |
||
56 | foreach ($values as $k => $v) { |
||
57 | $record->$k = $v; |
||
58 | } |
||
59 | $record->write(); |
||
60 | } |
||
61 | } |
||
62 | $newData = $data[$fieldName]['GridFieldAddNewInlineButton'] ?? []; |
||
63 | foreach ($newData as $idx => $values) { |
||
64 | if ($this->useHandleSave) { |
||
65 | /** @var \Symbiote\GridFieldExtensions\GridFieldAddNewInlineButton $component */ |
||
66 | $component = $gridField->getConfig()->getComponentByType(\Symbiote\GridFieldExtensions\GridFieldAddNewInlineButton::class); |
||
67 | $component->handleSave($gridField, $record); |
||
68 | } else { |
||
69 | $record = new $model; |
||
70 | foreach ($values as $k => $v) { |
||
71 | $record->$k = $v; |
||
72 | } |
||
73 | $record->write(); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | $response = $controller->getResponse(); |
||
78 | |||
79 | if (Director::is_ajax()) { |
||
80 | if (!$this->completeMessage) { |
||
81 | $this->completeMessage = _t('GridFieldSaveAllButton.DONE', 'All saved'); |
||
82 | } |
||
83 | if ($this->shouldReload) { |
||
84 | ActionsGridFieldItemRequest::addXReload($controller); |
||
85 | } |
||
86 | $response->addHeader('X-Status', rawurlencode($this->completeMessage)); |
||
87 | return null; |
||
88 | } else { |
||
89 | return $controller->redirectBack(); |
||
90 | } |
||
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