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