Completed
Push — master ( 4923e3...d627d1 )
by Joel
01:58
created
ConfirmationBehavior.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -223,7 +223,7 @@
 block discarded – undo
223 223
 
224 224
     /**
225 225
      * Adds a flash message to the interface stating the change has been held over pending confirmation.
226
-     * @param $model
226
+     * @param ConfirmationRequest $model
227 227
      */
228 228
     public function createFeedbackMessage($model){
229 229
         $this->displayMessage($model);
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      * @param $event Event;
91 91
      */
92 92
 
93
-    public function beforeSave($event){
93
+    public function beforeSave($event) {
94 94
         $this->protectAttributes();
95 95
     }
96 96
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
             if ($this->skipOnNull && $value === null || $attribute == $this->timestampAttribute)
110 110
                 continue;
111 111
 
112
-            if(!$this->isAuthorised($user, $attribute, $value)){
112
+            if (!$this->isAuthorised($user, $attribute, $value)) {
113 113
                 $this->createConfirmationRequest();
114 114
                 $this->resetAttribute($attribute);
115 115
             }
@@ -124,17 +124,17 @@  discard block
 block discarded – undo
124 124
      *
125 125
      * @return bool
126 126
      */
127
-    protected function isAuthorised($user, $attribute, $value){
127
+    protected function isAuthorised($user, $attribute, $value) {
128 128
 
129 129
         //Check for pre-defined administration roles
130 130
         if ($this->userIsAuthorised($user))
131 131
             return true;
132 132
 
133 133
         //Check for valid release token , eg that the token exists and is for the same record as this
134
-        if($this->releaseToken != null){
135
-            $confirmation =  ConfirmationRequest::findOne(['release_token' => $this->releaseToken]);
134
+        if ($this->releaseToken != null) {
135
+            $confirmation = ConfirmationRequest::findOne(['release_token' => $this->releaseToken]);
136 136
 
137
-            if($confirmation == null)
137
+            if ($confirmation == null)
138 138
                 return false;
139 139
 
140 140
             $model = $confirmation->constructObject();
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 
146 146
         //Check to see if any protected attributes have been altered
147 147
         foreach ($this->protectedAttributes as $attribute)
148
-            if($this->hasChanged($attribute))
148
+            if ($this->hasChanged($attribute))
149 149
                 return false;
150 150
 
151 151
         return true;
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
      *
158 158
      * @return bool
159 159
      */
160
-    protected function userIsAuthorised($user){
160
+    protected function userIsAuthorised($user) {
161 161
         foreach ($this->allow as $role)
162
-            if($user->can($role))
162
+            if ($user->can($role))
163 163
                 return true;
164 164
 
165 165
         return false;
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
     /**
169 169
      * Business logic handling the creation of the Confirmation Request, and sending the second factor message.
170 170
      */
171
-    protected function createConfirmationRequest(){
171
+    protected function createConfirmationRequest() {
172 172
 
173 173
         $model          = $this->owner;
174 174
         $changedValues  = $this->getChangedValues();
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
      *
194 194
      * @return bool
195 195
      */
196
-    protected function hasChanged($attribute){
196
+    protected function hasChanged($attribute) {
197 197
         return $this->owner->oldAttributes[$attribute] != $this->owner->{$attribute};
198 198
     }
199 199
 
@@ -201,11 +201,11 @@  discard block
 block discarded – undo
201 201
      * Fetches all values which have changed, expect for the timestamp attribute.
202 202
      * @return array
203 203
      */
204
-    public function getChangedValues(){
204
+    public function getChangedValues() {
205 205
         $changedAttributes = [];
206 206
 
207 207
         foreach ($this->owner->attributes() as $attribute)
208
-            if($this->hasChanged($attribute))
208
+            if ($this->hasChanged($attribute))
209 209
                 $changedAttributes[$attribute] = $this->owner->$attribute;
210 210
 
211 211
         unset($changedAttributes[$this->timestampAttribute]);
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
      * Sets an attribute back to it's original value when it was fetched.
218 218
      * @param string $attribute
219 219
      */
220
-    protected function resetAttribute($attribute){
220
+    protected function resetAttribute($attribute) {
221 221
         $this->owner->$attribute = $this->owner->oldAttributes[$attribute];
222 222
     }
223 223
 
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
      * Adds a flash message to the interface stating the change has been held over pending confirmation.
226 226
      * @param $model
227 227
      */
228
-    public function createFeedbackMessage($model){
228
+    public function createFeedbackMessage($model) {
229 229
         $this->displayMessage($model);
230 230
     }
231 231
 
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
      * Business logic around displaying an appropriate feedback message to the user regbarding the change.
234 234
      * @param $model
235 235
      */
236
-    protected function displayMessage($model){
236
+    protected function displayMessage($model) {
237 237
         Yii::$app->session->setFlash('warning', 'Your update is pending confirmation.  Please check your email for a confirmation link.');
238 238
     }
239 239
 
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
      * Business logic around transmitting the second factor message.
242 242
      * @param ConfirmationRequest $model
243 243
      */
244
-    public function sendSecondFactorMessage($model){
245
-        switch ($this->secondFactor){
244
+    public function sendSecondFactorMessage($model) {
245
+        switch ($this->secondFactor) {
246 246
             case 'email':
247 247
                 Yii::$app->mailer
248 248
                     ->compose($this->confirmationViewPath, ['model' => $model])
@@ -265,25 +265,25 @@  discard block
 block discarded – undo
265 265
      * @return string
266 266
      * @throws InvalidCallException
267 267
      */
268
-    protected function getEmail($model){
268
+    protected function getEmail($model) {
269 269
 
270 270
         $values = unserialize($model->values);
271
-        $email  = ArrayHelper::getValue($values,'email');
271
+        $email  = ArrayHelper::getValue($values, 'email');
272 272
         $object = $model->constructObject();
273 273
 
274
-        if($email == null)
275
-            $email = ArrayHelper::getValue($values,'email_address');
274
+        if ($email == null)
275
+            $email = ArrayHelper::getValue($values, 'email_address');
276 276
 
277
-        if($email == null)
278
-            $email = ArrayHelper::getValue($object,'email');
277
+        if ($email == null)
278
+            $email = ArrayHelper::getValue($object, 'email');
279 279
 
280
-        if($email == null)
281
-            $email = ArrayHelper::getValue($object,'email_address');
280
+        if ($email == null)
281
+            $email = ArrayHelper::getValue($object, 'email_address');
282 282
 
283
-        if($email == null)
284
-            $email = ArrayHelper::getValue($object,$this->createdByAttribute.'.email');
283
+        if ($email == null)
284
+            $email = ArrayHelper::getValue($object, $this->createdByAttribute . '.email');
285 285
 
286
-        if($email == null)
286
+        if ($email == null)
287 287
             throw new InvalidCallException("Unable to locate email address via record, changed values, or user account");
288 288
 
289 289
         return $email;
Please login to merge, or discard this patch.
Braces   +33 added lines, -22 removed lines patch added patch discarded remove patch
@@ -106,8 +106,9 @@  discard block
 block discarded – undo
106 106
 
107 107
         foreach ($changedValues as $attribute => $value) {
108 108
 
109
-            if ($this->skipOnNull && $value === null || $attribute == $this->timestampAttribute)
110
-                continue;
109
+            if ($this->skipOnNull && $value === null || $attribute == $this->timestampAttribute) {
110
+                            continue;
111
+            }
111 112
 
112 113
             if(!$this->isAuthorised($user, $attribute, $value)){
113 114
                 $this->createConfirmationRequest();
@@ -127,15 +128,17 @@  discard block
 block discarded – undo
127 128
     protected function isAuthorised($user, $attribute, $value){
128 129
 
129 130
         //Check for pre-defined administration roles
130
-        if ($this->userIsAuthorised($user))
131
-            return true;
131
+        if ($this->userIsAuthorised($user)) {
132
+                    return true;
133
+        }
132 134
 
133 135
         //Check for valid release token , eg that the token exists and is for the same record as this
134 136
         if($this->releaseToken != null){
135 137
             $confirmation =  ConfirmationRequest::findOne(['release_token' => $this->releaseToken]);
136 138
 
137
-            if($confirmation == null)
138
-                return false;
139
+            if($confirmation == null) {
140
+                            return false;
141
+            }
139 142
 
140 143
             $model = $confirmation->constructObject();
141 144
 
@@ -144,9 +147,10 @@  discard block
 block discarded – undo
144 147
         }
145 148
 
146 149
         //Check to see if any protected attributes have been altered
147
-        foreach ($this->protectedAttributes as $attribute)
148
-            if($this->hasChanged($attribute))
150
+        foreach ($this->protectedAttributes as $attribute) {
151
+                    if($this->hasChanged($attribute))
149 152
                 return false;
153
+        }
150 154
 
151 155
         return true;
152 156
     }
@@ -158,9 +162,10 @@  discard block
 block discarded – undo
158 162
      * @return bool
159 163
      */
160 164
     protected function userIsAuthorised($user){
161
-        foreach ($this->allow as $role)
162
-            if($user->can($role))
165
+        foreach ($this->allow as $role) {
166
+                    if($user->can($role))
163 167
                 return true;
168
+        }
164 169
 
165 170
         return false;
166 171
     }
@@ -204,9 +209,10 @@  discard block
 block discarded – undo
204 209
     public function getChangedValues(){
205 210
         $changedAttributes = [];
206 211
 
207
-        foreach ($this->owner->attributes() as $attribute)
208
-            if($this->hasChanged($attribute))
212
+        foreach ($this->owner->attributes() as $attribute) {
213
+                    if($this->hasChanged($attribute))
209 214
                 $changedAttributes[$attribute] = $this->owner->$attribute;
215
+        }
210 216
 
211 217
         unset($changedAttributes[$this->timestampAttribute]);
212 218
 
@@ -271,20 +277,25 @@  discard block
 block discarded – undo
271 277
         $email  = ArrayHelper::getValue($values,'email');
272 278
         $object = $model->constructObject();
273 279
 
274
-        if($email == null)
275
-            $email = ArrayHelper::getValue($values,'email_address');
280
+        if($email == null) {
281
+                    $email = ArrayHelper::getValue($values,'email_address');
282
+        }
276 283
 
277
-        if($email == null)
278
-            $email = ArrayHelper::getValue($object,'email');
284
+        if($email == null) {
285
+                    $email = ArrayHelper::getValue($object,'email');
286
+        }
279 287
 
280
-        if($email == null)
281
-            $email = ArrayHelper::getValue($object,'email_address');
288
+        if($email == null) {
289
+                    $email = ArrayHelper::getValue($object,'email_address');
290
+        }
282 291
 
283
-        if($email == null)
284
-            $email = ArrayHelper::getValue($object,$this->createdByAttribute.'.email');
292
+        if($email == null) {
293
+                    $email = ArrayHelper::getValue($object,$this->createdByAttribute.'.email');
294
+        }
285 295
 
286
-        if($email == null)
287
-            throw new InvalidCallException("Unable to locate email address via record, changed values, or user account");
296
+        if($email == null) {
297
+                    throw new InvalidCallException("Unable to locate email address via record, changed values, or user account");
298
+        }
288 299
 
289 300
         return $email;
290 301
     }
Please login to merge, or discard this patch.
ConfirmationRequestsController.php 2 patches
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -34,7 +34,6 @@  discard block
 block discarded – undo
34 34
 
35 35
     /**
36 36
      * Releases a single change as stored in the  ConfirmationRequest model.
37
-     * @param integer $id
38 37
      * @return mixed
39 38
      */
40 39
     public function actionRelease($release_token)
@@ -71,7 +70,6 @@  discard block
 block discarded – undo
71 70
     /**
72 71
      * Finds the ConfirmationRequest model based on its primary key value.
73 72
      * If the model is not found, a 404 HTTP exception will be thrown.
74
-     * @param integer $id
75 73
      * @return ConfirmationRequest the loaded model
76 74
      * @throws NotFoundHttpException if the model cannot be found
77 75
      */
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -40,30 +40,30 @@
 block discarded – undo
40 40
     public function actionRelease($release_token)
41 41
     {
42 42
 
43
-        try{
44
-            $model =  $this->findModel($release_token);
45
-        } catch (NotFoundHttpException $e){
46
-            Yii::$app->session->setFlash('danger' , "We were not able to find your change.  Perhaps it has already been processed?");
43
+        try {
44
+            $model = $this->findModel($release_token);
45
+        } catch (NotFoundHttpException $e) {
46
+            Yii::$app->session->setFlash('danger', "We were not able to find your change.  Perhaps it has already been processed?");
47 47
             return $this->goHome();
48 48
         }
49 49
 
50
-        try{
50
+        try {
51 51
             $model->release();
52
-        } catch (ErrorException $e){
52
+        } catch (ErrorException $e) {
53 53
             return $this->redirect(['confirmation-requests/expired']);
54 54
         }
55 55
 
56 56
         $viewLink = $model->constructObject()->getViewLink();
57 57
         $model->delete();
58 58
 
59
-        if(!Yii::$app->user->isGuest){
59
+        if (!Yii::$app->user->isGuest) {
60 60
             return $this->redirect($viewLink);
61 61
         }
62 62
 
63 63
         return $this->render('@vendor/enigmatix/yii2-confirmation/views/confirm', []);
64 64
     }
65 65
 
66
-    public function actionExpired(){
66
+    public function actionExpired() {
67 67
         return $this->render('@vendor/enigmatix/yii2-confirmation/views/expired', []);
68 68
 
69 69
     }
Please login to merge, or discard this patch.
mail/layouts/text.php 1 patch
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -1,7 +1,5 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-use yii\helpers\Html;
4
-
5 3
 /** @var \yii\web\View $this view component instance */
6 4
 /** @var \yii\mail\MessageInterface $message the message being composed */
7 5
 /** @var string $content main view render result */
Please login to merge, or discard this patch.
mail/_confirmationEmail.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,12 +3,12 @@
 block discarded – undo
3 3
 /* @var $model /yii/base/Model */
4 4
 use yii\helpers\Html;
5 5
 
6
-$link =  $model->getViewLink();
6
+$link = $model->getViewLink();
7 7
 ?>
8 8
 
9 9
 <p>Your details have been changed in <?=Yii::$app->name ?>. specifically:</p>
10 10
 
11
-  <?=  Html::ul(unserialize($model->values), ['item' => function($item, $index){return Html::tag('li', $index .' : ' . $item);}]) ?>
11
+  <?=  Html::ul(unserialize($model->values), ['item' => function($item, $index) {return Html::tag('li', $index . ' : ' . $item); }]) ?>
12 12
 
13 13
 <p>If these details are correct, please follow this link to 
14 14
     finalise your changes: <?= Html::a('Finalise link', $model->getViewLink()) ?></p>
Please login to merge, or discard this patch.
ConfirmationRequest.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
             [['object_id'], 'integer'],
39 39
             [['object', 'values'], 'string'],
40 40
             [['model', 'release_token'], 'string', 'max' => 255],
41
-            [['release_token'], 'default',  'value' => function ($model, $attribute){ return $this->generateReleaseToken();}],
41
+            [['release_token'], 'default', 'value' => function($model, $attribute) { return $this->generateReleaseToken(); }],
42 42
             [['created_by'], 'exist', 'skipOnError' => true, 'targetClass' => $this->getUserClassName(), 'targetAttribute' => ['created_by' => 'id']],
43 43
             [['updated_by'], 'exist', 'skipOnError' => true, 'targetClass' => $this->getUserClassName(), 'targetAttribute' => ['updated_by' => 'id']],
44 44
         ];
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
             ]);
85 85
     }
86 86
 
87
-    public function getViewLink(){
88
-        return Url::to(['@web/confirmation-requests', 'release_token' => $this->release_token],true);
87
+    public function getViewLink() {
88
+        return Url::to(['@web/confirmation-requests', 'release_token' => $this->release_token], true);
89 89
     }
90 90
 
91 91
     /**
@@ -113,20 +113,20 @@  discard block
 block discarded – undo
113 113
         return $this->hasOne($this->getUserClassName(), ['id' => 'updated_by']);
114 114
     }
115 115
 
116
-    protected function getUserClassName(){
116
+    protected function getUserClassName() {
117 117
         return Yii::$app->user->identityClass;
118 118
     }
119 119
 
120
-    public function release(){
120
+    public function release() {
121 121
 
122 122
         $model          = $this->constructObject();
123 123
         $changedValues  = $model->getChangedValues();
124 124
         $current        = clone $model;
125 125
         $current->refresh();
126 126
 
127
-        foreach ($changedValues as $field => $value){
127
+        foreach ($changedValues as $field => $value) {
128 128
             $oldValue = $model->oldAttributes[$field];
129
-            if($current->$field !== $oldValue && $current->$field !== $value)
129
+            if ($current->$field !== $oldValue && $current->$field !== $value)
130 130
                 throw new ErrorException("Unable to release change, protected field $field has been updated since this request."
131 131
                 . " Expected to find $value or $oldValue, found " . $current->$field);
132 132
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
     /**
142 142
      * @return \enigmatix\core\Model
143 143
      */
144
-    public function constructObject(){
144
+    public function constructObject() {
145 145
         return unserialize($this->object);
146 146
     }
147 147
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -126,9 +126,10 @@
 block discarded – undo
126 126
 
127 127
         foreach ($changedValues as $field => $value){
128 128
             $oldValue = $model->oldAttributes[$field];
129
-            if($current->$field !== $oldValue && $current->$field !== $value)
130
-                throw new ErrorException("Unable to release change, protected field $field has been updated since this request."
129
+            if($current->$field !== $oldValue && $current->$field !== $value) {
130
+                            throw new ErrorException("Unable to release change, protected field $field has been updated since this request."
131 131
                 . " Expected to find $value or $oldValue, found " . $current->$field);
132
+            }
132 133
 
133 134
         }
134 135
 
Please login to merge, or discard this patch.