YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/SharingAccess/models/RuleMember.php

Summary

Maintainability
B
6 hrs
Test Coverage
F
25%

Method getInstance has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function getInstance($qualifiedId)
    {
        $idComponents = self::getIdComponentsFromQualifiedId($qualifiedId);
        $type = $idComponents[0];
        $memberId = $idComponents[1];
Severity: Minor
Found in modules/Settings/SharingAccess/models/RuleMember.php - About 1 hr to fix

    Function getInstance has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function getInstance($qualifiedId)
        {
            $idComponents = self::getIdComponentsFromQualifiedId($qualifiedId);
            $type = $idComponents[0];
            $memberId = $idComponents[1];
    Severity: Minor
    Found in modules/Settings/SharingAccess/models/RuleMember.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

    Avoid too many return statements within this method.
    Open

            return false;
    Severity: Major
    Found in modules/Settings/SharingAccess/models/RuleMember.php - About 30 mins to fix

      Reduce the number of returns of this function 5, down to the maximum allowed 3.
      Open

          public static function getInstance($qualifiedId)

      Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

      Noncompliant Code Example

      With the default threshold of 3:

      function myFunction(){ // Noncompliant as there are 4 return statements
        if (condition1) {
          return true;
        } else {
          if (condition2) {
            return false;
          } else {
            return true;
          }
        }
        return false;
      }
      

      Missing class import via use statement (line '72', column '16').
      Open

                  $row = (new App\Db\Query())->from('vtiger_users')

      MissingImport

      Since: 2.7.0

      Importing all external classes in a file through use statements makes them clearly visible.

      Example

      function make() {
          return new \stdClass();
      }

      Source http://phpmd.org/rules/cleancode.html#MissingImport

      Missing class import via use statement (line '62', column '16').
      Open

                  $row = (new App\Db\Query())->from('vtiger_groups')

      MissingImport

      Since: 2.7.0

      Importing all external classes in a file through use statements makes them clearly visible.

      Example

      function make() {
          return new \stdClass();
      }

      Source http://phpmd.org/rules/cleancode.html#MissingImport

      Avoid using static access to class 'App\PrivilegeUtil' in method 'getInstance'.
      Open

                  $row = App\PrivilegeUtil::getRoleDetail($memberId);

      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 'Settings_Roles_Record_Model' in method 'getAll'.
      Open

              $allRoles = Settings_Roles_Record_Model::getAll();

      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 'Settings_Groups_Record_Model' in method 'getAll'.
      Open

              $allGroups = Settings_Groups_Record_Model::getAll();

      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 'Users_Record_Model' in method 'getAll'.
      Open

              $allUsers = Users_Record_Model::getAll();

      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 'App\PrivilegeUtil' in method 'getInstance'.
      Open

                  $row = App\PrivilegeUtil::getRoleDetail($memberId);

      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

      Argument 2 (str) is int but \explode() takes string
      Open

              return explode(':', $id);

      Call to undeclared method \App\Db\Query::from
      Open

                  $row = (new App\Db\Query())->from('vtiger_users')

      Saw unextractable annotation for comment '* @return <array> - Array of Settings_SharingAccess_RuleMember_Model instances'</array>
      Open

           * @return <Array> - Array of Settings_SharingAccess_RuleMember_Model instances

      Call to undeclared method \App\Db\Query::from
      Open

                  $row = (new App\Db\Query())->from('vtiger_groups')

      Saw unextractable annotation for comment '* @return <number> Id'</number>
      Open

           * @return <Number> Id

      Returning type false but getInstance() is declared to return \Settings_SharingAccess_RuleMember_Model
      Open

              return false;

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

              foreach ($allRoles as $roleId => $roleModel) {
                  $qualifiedId = self::getQualifiedId(self::RULE_MEMBER_TYPE_ROLES, $roleId);
                  $rule = new self();
                  $rules[self::RULE_MEMBER_TYPE_ROLES][$qualifiedId] = $rule->set('id', $qualifiedId)->set('name', $roleModel->getName());
      
      
      Severity: Major
      Found in modules/Settings/SharingAccess/models/RuleMember.php and 1 other location - About 3 hrs to fix
      modules/Settings/Groups/models/Member.php on lines 143..151

      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 148.

      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

      Each class must be in a namespace of at least one level (a top-level vendor name)
      Open

      class Settings_SharingAccess_RuleMember_Model extends \App\Base

      Avoid variables with short names like $id. Configured minimum length is 3.
      Open

          public static function getIdComponentsFromQualifiedId($id)

      ShortVariable

      Since: 0.2

      Detects when a field, local, or parameter has a very short name.

      Example

      class Something {
          private $q = 15; // VIOLATION - Field
          public static function main( array $as ) { // VIOLATION - Formal
              $r = 20 + $this->q; // VIOLATION - Local
              for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                  $r += $this->q;
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#shortvariable

      The class Settings_SharingAccess_RuleMember_Model is not named in CamelCase.
      Open

      class Settings_SharingAccess_RuleMember_Model extends \App\Base
      {
          const RULE_MEMBER_TYPE_GROUPS = 'Groups';
          const RULE_MEMBER_TYPE_ROLES = 'Roles';
          const RULE_MEMBER_TYPE_ROLE_AND_SUBORDINATES = 'RoleAndSubordinates';

      CamelCaseClassName

      Since: 0.2

      It is considered best practice to use the CamelCase notation to name classes.

      Example

      class class_name {
      }

      Source

      Avoid variables with short names like $id. Configured minimum length is 3.
      Open

          public static function getQualifiedId($type, $id)

      ShortVariable

      Since: 0.2

      Detects when a field, local, or parameter has a very short name.

      Example

      class Something {
          private $q = 15; // VIOLATION - Field
          public static function main( array $as ) { // VIOLATION - Formal
              $r = 20 + $this->q; // VIOLATION - Local
              for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                  $r += $this->q;
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#shortvariable

      Spaces must be used to indent lines; tabs are not allowed
      Open

          public function getId()

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  if ($row) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      ->one();

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $memberId = $idComponents[1];

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if (self::RULE_MEMBER_TYPE_GROUPS === $type) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      return (new self())->set('id', $qualifiedId)->set('name', $row['rolename']);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $row = App\PrivilegeUtil::getRoleDetail($memberId);

      Spaces must be used to indent lines; tabs are not allowed
      Open

              return $this->get('id');

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      ->where(['groupid' => $memberId])

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $idComponents = self::getIdComponentsFromQualifiedId($qualifiedId);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  if ($row) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

              return false;

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * Function to get the Group Name.

      Spaces must be used to indent lines; tabs are not allowed
      Open

          public static function getIdComponentsFromQualifiedId($id)

      Spaces must be used to indent lines; tabs are not allowed
      Open

          public static function getQualifiedId($type, $id)

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $qualifiedId = self::getQualifiedId(self::RULE_MEMBER_TYPE_USERS, $row['id']);

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

          public function getName()

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $row = (new App\Db\Query())->from('vtiger_groups')

      Spaces must be used to indent lines; tabs are not allowed
      Open

              return $this->get('name');

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * Function to get instance of class.

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }

      Spaces must be used to indent lines; tabs are not allowed
      Open

          const RULE_MEMBER_TYPE_USERS = 'Users';

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      ->one();

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }

      Spaces must be used to indent lines; tabs are not allowed
      Open

          const RULE_MEMBER_TYPE_GROUPS = 'Groups';

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {

      Spaces must be used to indent lines; tabs are not allowed
      Open

              return explode(':', $id);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $row = (new App\Db\Query())->from('vtiger_users')

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  if ($row) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $qualifiedId = self::getQualifiedId(self::RULE_MEMBER_TYPE_ROLES, $roleId);

      Spaces must be used to indent lines; tabs are not allowed
      Open

          /**

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      return (new self())->set('id', $qualifiedId)->set('name', $row['groupname']);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      ->where(['id' => $memberId])

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $rules[self::RULE_MEMBER_TYPE_ROLE_AND_SUBORDINATES][$qualifiedId] = $rule->set('id', $qualifiedId)->set('name', $roleModel->getName());

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }

      Spaces must be used to indent lines; tabs are not allowed
      Open

          public static function getInstance($qualifiedId)

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $qualifiedId = self::getQualifiedId(self::RULE_MEMBER_TYPE_ROLE_AND_SUBORDINATES, $row['roleid']);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $qualifiedId = self::getQualifiedId(self::RULE_MEMBER_TYPE_GROUPS, $groupId);

      Spaces must be used to indent lines; tabs are not allowed
      Open

          const RULE_MEMBER_TYPE_ROLES = 'Roles';

      Spaces must be used to indent lines; tabs are not allowed
      Open

          const RULE_MEMBER_TYPE_ROLE_AND_SUBORDINATES = 'RoleAndSubordinates';

      Spaces must be used to indent lines; tabs are not allowed
      Open

          /**

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @return string

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @return self

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $qualifiedId = self::getQualifiedId(self::RULE_MEMBER_TYPE_ROLES, $row['roleid']);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $rules[self::RULE_MEMBER_TYPE_ROLES][$qualifiedId] = $rule->set('id', $qualifiedId)->set('name', $roleModel->getName());

      Line exceeds 120 characters; contains 132 characters
      Open

                  $rules[self::RULE_MEMBER_TYPE_ROLES][$qualifiedId] = $rule->set('id', $qualifiedId)->set('name', $roleModel->getName());

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $qualifiedId = self::getQualifiedId(self::RULE_MEMBER_TYPE_ROLE_AND_SUBORDINATES, $roleId);

      Spaces must be used to indent lines; tabs are not allowed
      Open

          /**

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if (self::RULE_MEMBER_TYPE_ROLES === $type) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if (self::RULE_MEMBER_TYPE_ROLE_AND_SUBORDINATES === $type) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * Function to get all the rule members.

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @return <Array> - Array of Settings_SharingAccess_RuleMember_Model instances

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $rule = new self();

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $rule = new self();

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @return <Number> Id

      Spaces must be used to indent lines; tabs are not allowed
      Open

           */

      Spaces must be used to indent lines; tabs are not allowed
      Open

           */

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param int $qualifiedId

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

          /**

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }

      Spaces must be used to indent lines; tabs are not allowed
      Open

              return $type . ':' . $id;

      Spaces must be used to indent lines; tabs are not allowed
      Open

           */

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $type = $idComponents[0];

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $qualifiedId = self::getQualifiedId(self::RULE_MEMBER_TYPE_GROUPS, $row['groupid']);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      return (new self())->set('id', $qualifiedId)->set('name', $row['first_name'] . ' ' . $row['last_name']);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      return (new self())->set('id', $qualifiedId)->set('name', $row['rolename']);

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {

      Spaces must be used to indent lines; tabs are not allowed
      Open

          public static function getAll()

      Spaces must be used to indent lines; tabs are not allowed
      Open

              foreach ($allGroups as $groupId => $groupModel) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $rule = new self();

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $rule = new self();

      Line exceeds 120 characters; contains 139 characters
      Open

                  $rules[self::RULE_MEMBER_TYPE_USERS][$qualifiedId] = $rule->set('id', $qualifiedId)->set('name', $userModel->getDisplayName());

      Line exceeds 120 characters; contains 134 characters
      Open

                  $rules[self::RULE_MEMBER_TYPE_GROUPS][$qualifiedId] = $rule->set('id', $qualifiedId)->set('name', $groupModel->getName());

      Line exceeds 120 characters; contains 148 characters
      Open

                  $rules[self::RULE_MEMBER_TYPE_ROLE_AND_SUBORDINATES][$qualifiedId] = $rule->set('id', $qualifiedId)->set('name', $roleModel->getName());

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $allUsers = Users_Record_Model::getAll();

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * Function to get the Qualified Id of the Group RuleMember.

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if (self::RULE_MEMBER_TYPE_USERS === $type) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  if ($row) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $row = App\PrivilegeUtil::getRoleDetail($memberId);

      Spaces must be used to indent lines; tabs are not allowed
      Open

           */

      Spaces must be used to indent lines; tabs are not allowed
      Open

              return $rules;

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $allGroups = Settings_Groups_Record_Model::getAll();

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

              foreach ($allUsers as $userId => $userModel) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $rules[self::RULE_MEMBER_TYPE_USERS][$qualifiedId] = $rule->set('id', $qualifiedId)->set('name', $userModel->getDisplayName());

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $rules = [];

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $rules[self::RULE_MEMBER_TYPE_GROUPS][$qualifiedId] = $rule->set('id', $qualifiedId)->set('name', $groupModel->getName());

      Spaces must be used to indent lines; tabs are not allowed
      Open

              foreach ($allRoles as $roleId => $roleModel) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $qualifiedId = self::getQualifiedId(self::RULE_MEMBER_TYPE_USERS, $userId);

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $allRoles = Settings_Roles_Record_Model::getAll();

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Class name "Settings_SharingAccess_RuleMember_Model" is not in camel caps format
      Open

      class Settings_SharingAccess_RuleMember_Model extends \App\Base

      There are no issues that match your filters.

      Category
      Status