| Conditions | 10 |
| Paths | 31 |
| Total Lines | 39 |
| Code Lines | 23 |
| Lines | 11 |
| Ratio | 28.21 % |
| Changes | 5 | ||
| 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 |
||
| 30 | public function actionView($id = null, $slug = null) |
||
| 31 | { |
||
| 32 | $render = 'view'; |
||
| 33 | |||
| 34 | $comment = new Comment(); |
||
| 35 | |||
| 36 | if ($id) { |
||
|
|
|||
| 37 | $model = $this->findModel($id); |
||
| 38 | } elseif ($slug) { |
||
| 39 | $model = $this->findModelBySlug($slug); |
||
| 40 | } else { |
||
| 41 | throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.')); |
||
| 42 | } |
||
| 43 | |||
| 44 | View Code Duplication | if ($comment->load(Yii::$app->request->post()) && $comment->save()) { |
|
| 45 | if (!$comment->parent) { |
||
| 46 | $model->comment_count++; |
||
| 47 | } |
||
| 48 | if ($model->save()) { |
||
| 49 | $this->refresh(); |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | View Code Duplication | if ($model->password && $model->password !== Yii::$app->request->post('password')) { |
|
| 54 | return $this->render('protected', ['media' => $model]); |
||
| 55 | } |
||
| 56 | |||
| 57 | if (is_file($this->view->theme->basePath . '/media/view-' |
||
| 58 | . substr($model->mime_type, 0, strpos($model->mime_type, '/', 1)) . '.php') |
||
| 59 | ) { |
||
| 60 | $render = 'view-' . substr($model->mime_type, 0, strpos($model->mime_type, '/', 1)); |
||
| 61 | } |
||
| 62 | |||
| 63 | return $this->render($render, [ |
||
| 64 | 'media' => $model, |
||
| 65 | 'metadata' => $model->getMeta('metadata'), |
||
| 66 | 'comment' => $comment, |
||
| 67 | ]); |
||
| 68 | } |
||
| 69 | |||
| 104 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: