ConfirmationRequestsController::behaviors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace enigmatix\confirmation;
4
5
use yii\web\Controller;
6
use Yii;
7
use enigmatix\confirmation\ConfirmationRequest;
8
use yii\base\ErrorException;
9
use yii\web\NotFoundHttpException;
10
use yii\filters\VerbFilter;
11
12
/**
13
 * ConfirmationRequestsController implements the CRUD actions for ConfirmationRequest model.
14
 */
15
class ConfirmationRequestsController extends Controller
16
{
17
18
    var $defaultAction = 'release';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $defaultAction.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
19
    /**
20
     * @inheritdoc
21
     */
22
    public function behaviors()
23
    {
24
        return [
25
            'verbs' => [
26
                'class' => VerbFilter::className(),
27
                'actions' => [
28
                    'delete' => ['POST'],
29
                ],
30
            ],
31
        ];
32
    }
33
34
35
    /**
36
     * Releases a single change as stored in the  ConfirmationRequest model.
37
     * @return mixed
38
     */
39
    public function actionRelease($release_token)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $release_token is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
40
    {
41
42
        try {
43
            $model = $this->findModel($release_token);
44
        } catch (NotFoundHttpException $e) {
45
            Yii::$app->session->setFlash('danger', "We were not able to find your change.  Perhaps it has already been processed?");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal We were not able to find...already been processed? does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
46
            return $this->goHome();
47
        }
48
49
        try {
50
            $model->release();
51
        } catch (ErrorException $e) {
52
            return $this->redirect(['confirmation-requests/expired']);
53
        }
54
55
        $viewLink = $model->constructObject()->getViewLink();
56
        $model->delete();
57
58
        if (!Yii::$app->user->isGuest) {
59
            return $this->redirect($viewLink);
60
        }
61
62
        return $this->render('@vendor/enigmatix/yii2-confirmation/views/confirm', []);
63
    }
64
65
    public function actionExpired() {
66
        return $this->render('@vendor/enigmatix/yii2-confirmation/views/expired', []);
67
68
    }
69
70
    /**
71
     * Finds the ConfirmationRequest model based on its primary key value.
72
     * If the model is not found, a 404 HTTP exception will be thrown.
73
     * @return ConfirmationRequest the loaded model
74
     * @throws NotFoundHttpException if the model cannot be found
75
     */
76
    protected function findModel($release_token)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $release_token is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
77
    {
78
        if (($model = ConfirmationRequest::findOne(['release_token' => $release_token])) !== null) {
79
            return $model;
80
        } else {
81
            throw new NotFoundHttpException('The requested page does not exist.');
82
        }
83
    }
84
}
85