Completed
Push — master ( 6db6da...5370d9 )
by Angel
03:42
created

Restore   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 24
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 16 16 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace roaresearch\yii2\roa\actions;
4
5
use Yii;
6
use yii\web\ServerErrorHttpException;
7
8
/**
9
 * Restores a record using the `restoreDelete()` method. Meant to be used with
10
 * library "yii2tech/ar-softdelete".
11
 *
12
 * @author Angel (Faryshta) Guevara <[email protected]>
13
 */
14 View Code Duplication
class Restore extends Action
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    /**
17
     * Applies the `restore()` method to a record.
18
     *
19
     * @param mixed $id the identifier value.
20
     */
21
    public function run($id)
22
    {
23
        $this->checkAccess(
24
            ($model = $this->findModel($id)),
25
            Yii::$app->request->queryParams
26
        );
27
28
29
        if (false === $model->restore()) {
0 ignored issues
show
Bug introduced by
The method restore() does not seem to exist on object<yii\db\ActiveRecordInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
            throw new ServerErrorHttpException(
31
                'Failed to restore the object for unknown reason.'
32
            );
33
        }
34
35
        return $model;
36
    }
37
}
38