We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 10 |
| Paths | 13 |
| Total Lines | 41 |
| Code Lines | 24 |
| 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 |
||
| 103 | public static function applyCachedSetupClosure($crud) |
||
| 104 | { |
||
| 105 | $tableId = request('datatable_id'); |
||
| 106 | |||
| 107 | if (! $tableId) { |
||
| 108 | \Log::debug('Missing datatable_id in request parameters'); |
||
| 109 | |||
| 110 | return false; |
||
| 111 | } |
||
| 112 | |||
| 113 | $cacheKey = 'datatable_config_'.$tableId; |
||
| 114 | $cachedData = Cache::get($cacheKey); |
||
| 115 | |||
| 116 | if (! $cachedData) { |
||
| 117 | return false; |
||
| 118 | } |
||
| 119 | |||
| 120 | try { |
||
| 121 | // Get the parent crud instance |
||
| 122 | self::initializeOperations($cachedData['parentController'], $cachedData['operations']); |
||
| 123 | |||
| 124 | $entry = $cachedData['parent_entry']; |
||
| 125 | $elementName = $cachedData['element_name']; |
||
| 126 | $widgets = Widget::collection(); |
||
| 127 | foreach ($widgets as $widget) { |
||
| 128 | if ($widget['type'] === 'datatable' && |
||
| 129 | (isset($widget['name']) && $widget['name'] === $elementName) && |
||
| 130 | (isset($widget['setup']) && $widget['setup'] instanceof \Closure)) { |
||
| 131 | $widget['setup']($crud, $entry); |
||
| 132 | return true; |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | return false; |
||
| 137 | |||
| 138 | } catch (\Exception $e) { |
||
| 139 | \Log::error('Error applying cached datatable config: '.$e->getMessage(), [ |
||
| 140 | 'exception' => $e, |
||
| 141 | ]); |
||
| 142 | } |
||
| 143 | return false; |
||
| 144 | } |
||
| 165 |