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