Conditions | 10 |
Paths | 1 |
Total Lines | 33 |
Code Lines | 23 |
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 |
||
12 | protected static function bootHasSeo() |
||
13 | { |
||
14 | static::saved(function (Model $model) { |
||
15 | $options = $model->getSeoOptions(); |
||
16 | $seo = Seo::firstOrNew([ |
||
17 | 'type' => get_class($model), |
||
18 | 'object_id' => $model->{$model->primaryKey}, |
||
19 | ]); |
||
20 | $seo->slug = $options->routePrefix ?? ''; |
||
21 | if ($options->hasSlug) { |
||
22 | $seo->slug .= $model->{$options->slugField}; |
||
23 | } else { |
||
24 | $seo->slug .= $model->{$model->primaryKey}; |
||
25 | } |
||
26 | if (($title = request()->get('seo_title', false)) !== false) { |
||
27 | $seo->title = $title; |
||
28 | } else { |
||
29 | if ((empty($seo->title) || $options->overwriteOnUpdate) && isset($options->titleField)) { |
||
30 | $seo->title = $model->{$options->titleField}; |
||
31 | } |
||
32 | } |
||
33 | if (($description = request()->get('seo_description', false)) !== false) { |
||
34 | $seo->description = $description; |
||
35 | } else { |
||
36 | if ((empty($seo->description) || $options->overwriteOnUpdate) && isset($options->descriptionField)) { |
||
37 | $seo->description = $model->{$options->descriptionField}; |
||
38 | } |
||
39 | } |
||
40 | $seo->save(); |
||
41 | }); |
||
42 | |||
43 | static::retrieved(function (Model $model) { |
||
44 | app()->make('laravel-seo-meta-box')->addObjectOnPage(get_class($model), $model->{$model->primaryKey}); |
||
45 | }); |
||
53 |