Conditions | 11 |
Paths | 1 |
Total Lines | 36 |
Code Lines | 20 |
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 |
||
13 | public static function bootChangeByUser() |
||
14 | { |
||
15 | static::creating(function ($model) { |
||
16 | if (App::runningInConsole() || ! Auth::check()) { |
||
17 | return true; |
||
18 | } |
||
19 | if ($model->getCreatedByColumn()) { |
||
20 | $model->{$model->getUpdatedByColumn()} = Auth::user()->getKey(); |
||
21 | } |
||
22 | if ($model->getUpdatedByColumn()) { |
||
23 | $model->{$model->getUpdatedByColumn()} = Auth::user()->getKey(); |
||
24 | } |
||
25 | |||
26 | return true; |
||
27 | }); |
||
28 | |||
29 | static::updating(function ($model) { |
||
30 | if (App::runningInConsole() || ! Auth::check()) { |
||
31 | return true; |
||
32 | } |
||
33 | if ($model->getUpdatedByColumn()) { |
||
34 | $model->{$model->getUpdatedByColumn()} = Auth::user()->getKey(); |
||
35 | } |
||
36 | |||
37 | return true; |
||
38 | }); |
||
39 | |||
40 | static::deleting(function ($model) { |
||
41 | if (App::runningInConsole() || ! Auth::check()) { |
||
42 | return true; |
||
43 | } |
||
44 | if ($model->getDeletedByColumn()) { |
||
45 | $model->{$model->getDeletedByColumn()} = Auth::user()->getKey(); |
||
46 | } |
||
47 | |||
48 | return true; |
||
49 | }); |
||
67 |