Conditions | 2 |
Paths | 1 |
Total Lines | 52 |
Code Lines | 35 |
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 |
||
22 | public function actions() |
||
23 | { |
||
24 | return array_merge(parent::actions(), [ |
||
25 | 'create' => [ |
||
26 | 'class' => SmartCreateAction::class, |
||
27 | 'data' => function ($action, $data) { |
||
28 | $plan = null; |
||
29 | if ($plan_id = Yii::$app->request->get('plan_id')) { |
||
30 | $plan = Plan::findOne(['id' => $plan_id]); |
||
31 | } |
||
32 | |||
33 | return compact('plan'); |
||
34 | }, |
||
35 | 'success' => Yii::t('hipanel.finance.price', 'Prices were successfully created') |
||
36 | ], |
||
37 | 'create-suggested' => [ |
||
38 | 'class' => SmartCreateAction::class, |
||
39 | 'scenario' => 'create', |
||
40 | 'POST' => [ |
||
41 | 'save' => true, |
||
42 | 'success' => [ |
||
43 | 'class' => RedirectAction::class, |
||
44 | 'url' => function (RedirectAction $action) { |
||
45 | return ['@plan/view', 'id' => $action->collection->getModel()->plan_id]; |
||
46 | }, |
||
47 | ], |
||
48 | ], |
||
49 | 'success' => Yii::t('hipanel.finance.price', 'Prices were successfully created') |
||
50 | ], |
||
51 | 'update' => [ |
||
52 | 'class' => SmartUpdateAction::class, |
||
53 | 'success' => Yii::t('hipanel.finance.price', 'Prices were successfully updated') |
||
54 | ], |
||
55 | 'index' => [ |
||
56 | 'class' => IndexAction::class, |
||
57 | ], |
||
58 | 'view' => [ |
||
59 | 'class' => ViewAction::class, |
||
60 | ], |
||
61 | 'delete' => [ |
||
62 | 'class' => SmartDeleteAction::class, |
||
63 | 'success' => Yii::t('hipanel.finance.price', 'Prices were successfully deleted') |
||
64 | ], |
||
65 | 'set-note' => [ |
||
66 | 'class' => SmartUpdateAction::class, |
||
67 | 'success' => Yii::t('hipanel', 'Note changed'), |
||
68 | ], |
||
69 | 'validate-form' => [ |
||
70 | 'class' => ValidateFormAction::class, |
||
71 | ], |
||
72 | ]); |
||
73 | } |
||
74 | |||
103 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.