iranianpep/code-jetter

View on GitHub
components/user/controllers/MemberUserController.php

Summary

Maintainability
F
4 days
Test Coverage

File MemberUserController.php has 434 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace CodeJetter\components\user\controllers;

use CodeJetter\components\page\models\Page;
Severity: Minor
Found in components/user/controllers/MemberUserController.php - About 6 hrs to fix

    The class MemberUserController has 17 public methods. Consider refactoring MemberUserController to keep number of public methods under 10.
    Open

    class MemberUserController extends BaseController
    {
        /**
         * Generate register form.
         *

    TooManyPublicMethods

    Since: 0.1

    A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

    By default it ignores methods starting with 'get' or 'set'.

    Example

    Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

    Method listUsers has 68 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function listUsers()
        {
            // for pagination - for simple router url path is enough, for regex ones base path is needed
            $pager = new Pager($this->getURLParameters(), $this->getBasePath(), $this->getRouteInfo()->getUrl());
    
    
    Severity: Major
    Found in components/user/controllers/MemberUserController.php - About 2 hrs to fix

      Method viewChild has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function viewChild()
          {
              $urlParameters = $this->getURLParameters();
      
              if (empty($urlParameters['id'])) {
      Severity: Major
      Found in components/user/controllers/MemberUserController.php - About 2 hrs to fix

        Method safeBatchDeleteChild has 55 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function safeBatchDeleteChild()
            {
                $inputs = (new Request('POST'))->getInputs();
        
                /**
        Severity: Major
        Found in components/user/controllers/MemberUserController.php - About 2 hrs to fix

          Function viewChild has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              public function viewChild()
              {
                  $urlParameters = $this->getURLParameters();
          
                  if (empty($urlParameters['id'])) {
          Severity: Minor
          Found in components/user/controllers/MemberUserController.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

          Method safeDeleteChild has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function safeDeleteChild()
              {
                  $inputs = (new Request('POST'))->getInputs();
          
                  if (empty($inputs['id'])) {
          Severity: Minor
          Found in components/user/controllers/MemberUserController.php - About 1 hr to fix

            Method profileForm has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function profileForm()
                {
                    $currentUser = (new MemberUser())->getLoggedIn();
            
                    /**
            Severity: Minor
            Found in components/user/controllers/MemberUserController.php - About 1 hr to fix

              Function safeBatchDeleteChild has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function safeBatchDeleteChild()
                  {
                      $inputs = (new Request('POST'))->getInputs();
              
                      /**
              Severity: Minor
              Found in components/user/controllers/MemberUserController.php - About 25 mins 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 method listUsers() has 104 lines of code. Current threshold is set to 100. Avoid really long methods.
              Open

                  public function listUsers()
                  {
                      // for pagination - for simple router url path is enough, for regex ones base path is needed
                      $pager = new Pager($this->getURLParameters(), $this->getBasePath(), $this->getRouteInfo()->getUrl());
              
              

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

              class MemberUserController extends BaseController
              {
                  /**
                   * Generate register form.
                   *

              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

              Avoid using static access to class '\CodeJetter\core\Registry' in method 'viewChild'.
              Open

                      $language = Registry::getLanguageClass();

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

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

              Avoid using static access to class '\CodeJetter\core\Registry' in method 'profileForm'.
              Open

                      $language = Registry::getLanguageClass();

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

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

              Avoid using static access to class '\CodeJetter\core\Registry' in method 'registerForm'.
              Open

                      $language = Registry::getLanguageClass();

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

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

              Avoid using static access to class '\CodeJetter\core\Registry' in method 'listUsers'.
              Open

                      $language = Registry::getLanguageClass();

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

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

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

                      } else {
                          $member = '';
                      }

              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

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  public function profileForm()
                  {
                      $currentUser = (new MemberUser())->getLoggedIn();
              
                      /**
              Severity: Major
              Found in components/user/controllers/MemberUserController.php and 1 other location - About 6 hrs to fix
              components/user/controllers/AdminUserController.php on lines 627..667

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 216.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  public function resetPasswordForm()
                  {
                      $inputs = $this->getURLParameters();
                      $output = (new MemberUser())->checkTokenIsValidByEmail($inputs['email'], $inputs['token']);
              
              
              Severity: Major
              Found in components/user/controllers/MemberUserController.php and 1 other location - About 4 hrs to fix
              components/user/controllers/AdminUserController.php on lines 579..604

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 177.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  public function loginForm()
                  {
                      $page = new Page($this->getRouteInfo()->getAccessRole());
                      $page->setTitle('Login');
              
              
              Severity: Major
              Found in components/user/controllers/MemberUserController.php and 1 other location - About 2 hrs to fix
              components/user/controllers/AdminUserController.php on lines 42..70

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 140.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  public function forgotPasswordForm()
                  {
                      $page = new Page($this->getRouteInfo()->getAccessRole());
                      $page->setTitle('Forgot your password');
              
              
              Severity: Major
              Found in components/user/controllers/MemberUserController.php and 1 other location - About 2 hrs to fix
              components/user/controllers/AdminUserController.php on lines 545..572

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 135.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 3 locations. Consider refactoring.
              Open

                      if ($output instanceof Output and (int) $output->getData() > 0) {
                          // delete group xrefs if user is deleted
                          // safe delete the group xrefs first, if there is any
                          (new GroupMemberUserXrefMapper())->safeDelete([
                              [
              Severity: Major
              Found in components/user/controllers/MemberUserController.php and 2 other locations - About 1 hr to fix
              components/user/controllers/AdminUserController.php on lines 303..320
              components/user/controllers/MemberGroupController.php on lines 237..252

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 116.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                  public function resetPassword()
                  {
                      $inputs = (new Request('POST'))->getInputs(['email', 'resetPasswordToken', 'password', 'passwordConfirmation']);
                      $output = (new MemberUser())->resetPassword(
                          $inputs['email'],
              Severity: Minor
              Found in components/user/controllers/MemberUserController.php and 1 other location - About 45 mins to fix
              components/user/controllers/AdminUserController.php on lines 609..620

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 95.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 34 and the first side effect is on line 28.
              Open

              <?php

              There are no issues that match your filters.

              Category
              Status