Completed
Pull Request — master (#2)
by Angel
03:03
created

SafeDelete   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 15 15 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
 * Deletes a record using the `safeDelete()` 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 SafeDelete 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 `softDelete()` 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
        if (false === $model->safeDelete()) {
0 ignored issues
show
Bug introduced by
The method safeDelete() does not exist on yii\db\ActiveRecordInterface. Did you maybe mean delete()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
29
            throw new ServerErrorHttpException(
30
                'Failed to delete the object for unknown reason.'
31
            );
32
        }
33
34
        Yii::$app->getResponse()->setStatusCode(204);
35
    }
36
}
37