Conditions | 9 |
Paths | 2 |
Total Lines | 51 |
Code Lines | 23 |
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 |
||
30 | protected static function bootUserIdentities() |
||
31 | { |
||
32 | // Creating |
||
33 | static::creating(function (Model $model) { |
||
34 | if (! $model->usesUserIdentities()) { |
||
35 | return; |
||
36 | } |
||
37 | |||
38 | if (is_null($model->{$model->columnCreatedBy})) { |
||
39 | $model->{$model->columnCreatedBy} = auth()->id(); |
||
1 ignored issue
–
show
|
|||
40 | } |
||
41 | |||
42 | if (is_null($model->{$model->columnUpdatedBy})) { |
||
43 | $model->{$model->columnUpdatedBy} = auth()->id(); |
||
44 | } |
||
45 | }); |
||
46 | |||
47 | // Updating |
||
48 | static::updating(function (Model $model) { |
||
49 | if (! $model->usesUserIdentities()) { |
||
50 | return; |
||
51 | } |
||
52 | |||
53 | $model->{$model->columnUpdatedBy} = auth()->id(); |
||
1 ignored issue
–
show
|
|||
54 | }); |
||
55 | |||
56 | // Delete/Restore |
||
57 | if (static::usingSoftDeletes()) { |
||
58 | |||
59 | static::deleting(function (Model $model) { |
||
60 | if (! $model->usesUserIdentities()) { |
||
61 | return; |
||
62 | } |
||
63 | |||
64 | if (is_null($model->{$model->columnDeletedBy})) { |
||
65 | $model->{$model->columnDeletedBy} = auth()->id(); |
||
1 ignored issue
–
show
|
|||
66 | } |
||
67 | |||
68 | $model->save(); |
||
69 | }); |
||
70 | |||
71 | static::restoring(function (Model $model) { |
||
72 | if (! $model->usesUserIdentities()) { |
||
73 | return; |
||
74 | } |
||
75 | |||
76 | $model->{$model->columnDeletedBy} = null; |
||
77 | }); |
||
78 | } |
||
79 | |||
80 | } |
||
81 | |||
136 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: