Rafalsky/HomeFinance

View on GitHub
frontend/modules/user/controllers/SignInController.php

Summary

Maintainability
C
1 day
Test Coverage

actionLogin accesses the super-global variable $_POST.
Open

    public function actionLogin()
    {
        $model = new LoginForm();
        if (\Yii::$app->request->isAjax) {
            $model->load($_POST);

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

Method successOAuthCallback has 66 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function successOAuthCallback($client)
    {
        // use BaseClient::normalizeUserAttributeMap to provide consistency for user attribute`s names
        $attributes = $client->getUserAttributes();
        $user = User::find()->where([
Severity: Major
Found in frontend/modules/user/controllers/SignInController.php - About 2 hrs to fix

    Function successOAuthCallback has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        public function successOAuthCallback($client)
        {
            // use BaseClient::normalizeUserAttributeMap to provide consistency for user attribute`s names
            $attributes = $client->getUserAttributes();
            $user = User::find()->where([
    Severity: Minor
    Found in frontend/modules/user/controllers/SignInController.php - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    File SignInController.php has 254 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    /*
     * This file is part of the HomeFinanceV2 project.
     *
    Severity: Minor
    Found in frontend/modules/user/controllers/SignInController.php - About 2 hrs to fix

      Method behaviors has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function behaviors()
          {
              return [
                  'access' => [
                      'class' => AccessControl::className(),
      Severity: Minor
      Found in frontend/modules/user/controllers/SignInController.php - About 1 hr to fix

        Method actionSignup has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function actionSignup()
            {
                $model = new SignupForm();
                if ($model->load(\Yii::$app->request->post())) {
                    $user = $model->signup();
        Severity: Minor
        Found in frontend/modules/user/controllers/SignInController.php - About 1 hr to fix

          Function actionSignup has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              public function actionSignup()
              {
                  $model = new SignupForm();
                  if ($model->load(\Yii::$app->request->post())) {
                      $user = $model->signup();
          Severity: Minor
          Found in frontend/modules/user/controllers/SignInController.php - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          The class SignInController has a coupling between objects value of 17. Consider to reduce the number of dependencies under 13.
          Open

          class SignInController extends \yii\web\Controller
          {
              /**
               * @return array
               */

          CouplingBetweenObjects

          Since: 1.1.0

          A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

          Example

          class Foo {
              /**
               * @var \foo\bar\X
               */
              private $x = null;
          
              /**
               * @var \foo\bar\Y
               */
              private $y = null;
          
              /**
               * @var \foo\bar\Z
               */
              private $z = null;
          
              public function setFoo(\Foo $foo) {}
              public function setBar(\Bar $bar) {}
              public function setBaz(\Baz $baz) {}
          
              /**
               * @return \SplObjectStorage
               * @throws \OutOfRangeException
               * @throws \InvalidArgumentException
               * @throws \ErrorException
               */
              public function process(\Iterator $it) {}
          
              // ...
          }

          Source https://phpmd.org/rules/design.html#couplingbetweenobjects

          The method successOAuthCallback uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                      } else {
                          // We already have a user with this email. Do what you want in such case
                          if ($user->email && User::find()->where(['email' => $user->email])->count()) {
                              \Yii::$app->session->setFlash(
                                  'alert',

          ElseExpression

          Since: 1.4.0

          An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

          Example

          class Foo
          {
              public function bar($flag)
              {
                  if ($flag) {
                      // one branch
                  } else {
                      // another branch
                  }
              }
          }

          Source https://phpmd.org/rules/cleancode.html#elseexpression

          The method actionRequestPasswordReset uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                      } else {
                          \Yii::$app->getSession()->setFlash('alert', [
                              'body' => \Yii::t('frontend', 'Sorry, we are unable to reset password for email provided.'),
                              'options'=>['class' => 'alert-danger']
                          ]);

          ElseExpression

          Since: 1.4.0

          An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

          Example

          class Foo
          {
              public function bar($flag)
              {
                  if ($flag) {
                      // one branch
                  } else {
                      // another branch
                  }
              }
          }

          Source https://phpmd.org/rules/cleancode.html#elseexpression

          The method successOAuthCallback uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      throw new Exception('OAuth error');
                  }

          ElseExpression

          Since: 1.4.0

          An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

          Example

          class Foo
          {
              public function bar($flag)
              {
                  if ($flag) {
                      // one branch
                  } else {
                      // another branch
                  }
              }
          }

          Source https://phpmd.org/rules/cleancode.html#elseexpression

          The method successOAuthCallback uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                          } else {
                              \Yii::$app->session->setFlash(
                                  'alert',
                                  [
                                      'options' => ['class' => 'alert-danger'],

          ElseExpression

          Since: 1.4.0

          An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

          Example

          class Foo
          {
              public function bar($flag)
              {
                  if ($flag) {
                      // one branch
                  } else {
                      // another branch
                  }
              }
          }

          Source https://phpmd.org/rules/cleancode.html#elseexpression

          The method actionLogin uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      return $this->render('login', [
                          'model' => $model
                      ]);
                  }

          ElseExpression

          Since: 1.4.0

          An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

          Example

          class Foo
          {
              public function bar($flag)
              {
                  if ($flag) {
                      // one branch
                  } else {
                      // another branch
                  }
              }
          }

          Source https://phpmd.org/rules/cleancode.html#elseexpression

          The method actionSignup uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                          } else {
                              \Yii::$app->getSession()->setFlash('alert', [
                                  'body' => \Yii::t(
                                      'frontend',
                                      'Your account has been successfully created.'

          ElseExpression

          Since: 1.4.0

          An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

          Example

          class Foo
          {
              public function bar($flag)
              {
                  if ($flag) {
                      // one branch
                  } else {
                      // another branch
                  }
              }
          }

          Source https://phpmd.org/rules/cleancode.html#elseexpression

          There are no issues that match your filters.

          Category
          Status