We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 13 |
| Paths | 27 |
| Total Lines | 71 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 82 | public static function applyCachedConfig($crud) |
||
| 83 | { |
||
| 84 | $tableId = request('datatable_id'); |
||
| 85 | |||
| 86 | if (!$tableId) { |
||
| 87 | \Log::debug('Missing datatable_id in request parameters'); |
||
| 88 | return false; |
||
| 89 | } |
||
| 90 | |||
| 91 | $cacheKey = 'datatable_config_' . $tableId; |
||
| 92 | $cachedData = Cache::get($cacheKey); |
||
| 93 | |||
| 94 | if (!$cachedData) { |
||
| 95 | \Log::debug('No cached configuration found for the given datatable_id'); |
||
| 96 | return false; |
||
| 97 | } |
||
| 98 | |||
| 99 | try { |
||
| 100 | \Log::debug('Found matching configuration by table ID', [ |
||
| 101 | 'controller' => $cachedData['controller'], |
||
| 102 | 'element_type' => $cachedData['element_type'], |
||
| 103 | 'element_name' => $cachedData['element_name'], |
||
| 104 | 'table_id' => $tableId |
||
| 105 | ]); |
||
| 106 | |||
| 107 | // Get the parent crud instance |
||
| 108 | $parentCrud = CrudManager::crudFromController($cachedData['parentController'], 'show'); |
||
| 109 | $entry = $cachedData['parent_entry']; |
||
| 110 | |||
| 111 | // Get element type and name from cached data |
||
| 112 | $elementType = $cachedData['element_type']; |
||
| 113 | $elementName = $cachedData['element_name']; |
||
| 114 | |||
| 115 | \Log::debug('Element type and name', [ |
||
| 116 | 'element_type' => $elementType, |
||
| 117 | 'element_name' => $elementName |
||
| 118 | ]); |
||
| 119 | |||
| 120 | if ($elementType === 'column') { |
||
| 121 | $column = $parentCrud->columns()[$elementName] ?? null; |
||
| 122 | if ($column && isset($column['configure'])) { |
||
| 123 | self::applyColumnDatatableConfig($parentCrud, $crud, $elementName, $entry); |
||
| 124 | // clear the cache after applying the configuration |
||
| 125 | Cache::forget($cacheKey); |
||
| 126 | return true; |
||
| 127 | } |
||
| 128 | \Log::debug('Column not found or no configure closure defined'); |
||
| 129 | return false; |
||
| 130 | } else if ($elementType === 'widget') { |
||
| 131 | $widgets = $parentCrud->getOperationSetting('widgets') ?? []; |
||
| 132 | foreach ($widgets as $widget) { |
||
| 133 | if ($widget['type'] === 'datatable' && |
||
| 134 | (isset($widget['name']) && $widget['name'] === $elementName) && |
||
| 135 | isset($widget['configure'])) { |
||
| 136 | self::applyWidgetDatatableConfig($parentCrud, $crud, $elementName, $entry); |
||
| 137 | // clear the cache after applying the configuration |
||
| 138 | Cache::forget($cacheKey); |
||
| 139 | return true; |
||
| 140 | } |
||
| 141 | } |
||
| 142 | \Log::debug('Widget not found or no configure closure defined'); |
||
| 143 | return false; |
||
| 144 | } |
||
| 145 | } catch (\Exception $e) { |
||
| 146 | \Log::error("Error applying cached datatable config: " . $e->getMessage(), [ |
||
| 147 | 'exception' => $e |
||
| 148 | ]); |
||
| 149 | } |
||
| 150 | |||
| 151 | \Log::debug('No matching configuration found'); |
||
| 152 | return false; |
||
| 153 | } |
||
| 187 | } |