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