These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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
|
|||
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
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 ![]() |
|||
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 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 ( 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: 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. ![]() |
|||
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
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 ![]() |
|||
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 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.