| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace yiicod\auth\actions\webUser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Yii; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use yii\base\Action; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use yii\base\Event; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use yii\base\InvalidParamException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use yiicod\auth\events\ResetPasswordErrorEvent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use yiicod\auth\events\ResetPasswordEvent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class ResetPasswordAction extends Action | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     const EVENT_BEFORE_RESET_PASSWORD = 'beforeResetPassword'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     const EVENT_AFTER_RESET_PASSWORD = 'afterResetPassword'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     const EVENT_ERROR_RESET_PASSWORD = 'errorResetPassword'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     public $view = '@yiicod/yii2-auth/views/webUser/resetPassword'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     public function run($token) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $model = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $resetPasswordFormClass = Yii::$app->get('auth')->modelMap['resetPasswordForm']['class']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         Event::trigger(self::class, static::EVENT_BEFORE_RESET_PASSWORD, new ResetPasswordEvent($this, $model, ['sender' => $this])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             $model = new $resetPasswordFormClass($token); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         } catch (InvalidParamException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             Event::trigger(self::class, static::EVENT_ERROR_RESET_PASSWORD, new ResetPasswordErrorEvent($this, $token, $e, ['sender' => $this])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         if ($model instanceof $resetPasswordFormClass && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             $model->load(Yii::$app->request->post()) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             $model->validate() && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             $model->resetPassword() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             Event::trigger(self::class, static::EVENT_AFTER_RESET_PASSWORD, new ResetPasswordEvent($this, $model, ['sender' => $this])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         return $this->controller->render($this->view, [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             'model' => $model, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | //    public function trigger($name, Event $event = null) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | //    { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | //        Yii::$app->trigger(sprintf('yiicod.auth.actions.webUser.ResetPasswordAction.%s', $name), $event); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 49 |  |  | //        return parent::trigger($name, $event); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 50 |  |  | //    } | 
            
                                                        
            
                                    
            
            
                | 51 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |  | 
            
                        
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.