We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 10 |
Paths | 16 |
Total Lines | 51 |
Code Lines | 28 |
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 |
||
88 | public static function applyCachedConfigurationClosure($crud) |
||
89 | { |
||
90 | $tableId = request('datatable_id'); |
||
91 | |||
92 | if (! $tableId) { |
||
93 | \Log::debug('Missing datatable_id in request parameters'); |
||
94 | |||
95 | return false; |
||
96 | } |
||
97 | |||
98 | $cacheKey = 'datatable_config_'.$tableId; |
||
99 | $cachedData = Cache::get($cacheKey); |
||
100 | |||
101 | if (! $cachedData) { |
||
102 | \Log::debug('No cached configuration found for the given datatable_id'); |
||
103 | |||
104 | return false; |
||
105 | } |
||
106 | |||
107 | try { |
||
108 | // Get the parent crud instance |
||
109 | $parentCrud = CrudManager::crudFromController($cachedData['parentController'], 'show'); |
||
110 | $entry = $cachedData['parent_entry']; |
||
111 | |||
112 | // Get element type and name from cached data |
||
113 | $elementType = $cachedData['element_type']; |
||
114 | $elementName = $cachedData['element_name']; |
||
115 | |||
116 | if ($elementType === 'widget') { |
||
117 | $widgets = $parentCrud->getOperationSetting('widgets') ?? []; |
||
118 | foreach ($widgets as $widget) { |
||
119 | if ($widget['type'] === 'datatable' && |
||
120 | (isset($widget['name']) && $widget['name'] === $elementName) && |
||
121 | isset($widget['configure'])) { |
||
122 | self::applyWidgetDatatableConfig($parentCrud, $crud, $elementName, $entry); |
||
123 | // clear the cache after applying the configuration |
||
124 | Cache::forget($cacheKey); |
||
125 | |||
126 | return true; |
||
127 | } |
||
128 | } |
||
129 | |||
130 | return false; |
||
131 | } |
||
132 | } catch (\Exception $e) { |
||
133 | \Log::error('Error applying cached datatable config: '.$e->getMessage(), [ |
||
134 | 'exception' => $e, |
||
135 | ]); |
||
136 | } |
||
137 | |||
138 | return false; |
||
139 | } |
||
166 |