| Conditions | 10 |
| Paths | 25 |
| Total Lines | 48 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 32 | public function post($params) |
||
| 33 | { |
||
| 34 | static $form; |
||
| 35 | if ($this->scenario === null || $this->scenario === static::SCENARIO_TOKENIZED) { |
||
| 36 | $token = Yii::$app->request->get('reset_token', false); |
||
| 37 | |||
| 38 | // Determine the correct scenario to use based upon the reset token |
||
| 39 | if ($token === false) { |
||
| 40 | $form = new ResetPassword(['scenario' => ResetPassword::SCENARIO_INIT]); |
||
| 41 | } else { |
||
| 42 | $form = new ResetPassword(['scenario' => ResetPassword::SCENARIO_RESET]); |
||
| 43 | } |
||
| 44 | |||
| 45 | // If the user is authenticated, populate the model |
||
| 46 | if (!Yii::$app->user->isGuest) { |
||
| 47 | $user = Yii::$app->user->identityClass::findOne(['id' => Yii::$app->user->id]); |
||
| 48 | $form->setUser($user); |
||
| 49 | } else { |
||
| 50 | $form->email = Yii::$app->request->post('email', null); |
||
| 51 | } |
||
| 52 | |||
| 53 | $form->reset_token = Yii::$app->request->get('reset_token', null); |
||
| 54 | } elseif ($this->scenario === static::SCENARIO_AUTHENTICATED) { |
||
| 55 | if (Yii::$app->user->isGuest) { |
||
| 56 | throw new HttpException(400, Yii::t('yrc', 'You must be authenticated to reset your password')); |
||
| 57 | return; |
||
| 58 | } |
||
| 59 | |||
| 60 | $form = new ResetPassword(['scenario' => ResetPassword::SCENARIO_RESET_AUTHENTICATED]); |
||
| 61 | $form->user_id = Yii::$app->user->id; |
||
| 62 | } |
||
| 63 | |||
| 64 | // Load the model using the helper method |
||
| 65 | if (self::load($form, Yii::$app->request->post())) { |
||
| 66 | // If the form is valid, reset the password |
||
| 67 | if ($form->validate()) { |
||
| 68 | return $form->reset(); |
||
| 69 | } |
||
| 70 | |||
| 71 | // If a password reset was requested, (init) return true ALWAYS |
||
| 72 | if ($form->getScenario() === ResetPassword::SCENARIO_INIT) { |
||
| 73 | return true; |
||
| 74 | } |
||
| 75 | |||
| 76 | throw new HttpException(400, \json_encode($form->getErrors())); |
||
| 77 | } |
||
| 78 | |||
| 79 | return false; |
||
| 80 | } |
||
| 93 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths