Admidio/admidio

View on GitHub
adm_program/system/classes/TableRoles.php

Summary

Maintainability
F
4 days
Test Coverage

Function setMembership has a Cognitive Complexity of 65 (exceeds 5 allowed). Consider refactoring.
Open

    public function setMembership(int $userId, string $startDate, string $endDate, ?bool $leader = null, bool $forcePeriod = false)
    {
        global $gCurrentUser, $gCurrentUserId, $gCurrentSession;

        $newMembershipSaved = false;
Severity: Minor
Found in adm_program/system/classes/TableRoles.php - About 1 day 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 TableRoles.php has 504 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
use Admidio\Exception;

/**
 * @brief Class manages access to database table adm_roles
Severity: Major
Found in adm_program/system/classes/TableRoles.php - About 1 day to fix

    Method setMembership has 130 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function setMembership(int $userId, string $startDate, string $endDate, ?bool $leader = null, bool $forcePeriod = false)
        {
            global $gCurrentUser, $gCurrentUserId, $gCurrentSession;
    
            $newMembershipSaved = false;
    Severity: Major
    Found in adm_program/system/classes/TableRoles.php - About 5 hrs to fix

      Function setValue has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

          public function setValue(string $columnName, $newValue, bool $checkValue = true): bool
          {
              global $gL10n, $gCurrentUser;
      
              if ($checkValue) {
      Severity: Minor
      Found in adm_program/system/classes/TableRoles.php - About 4 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

      TableRoles has 22 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class TableRoles extends TableAccess
      {
          public const ROLE_GROUP = 0;
          public const ROLE_EVENT = 1;
      
      
      Severity: Minor
      Found in adm_program/system/classes/TableRoles.php - About 2 hrs to fix

        Method setValue has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function setValue(string $columnName, $newValue, bool $checkValue = true): bool
            {
                global $gL10n, $gCurrentUser;
        
                if ($checkValue) {
        Severity: Minor
        Found in adm_program/system/classes/TableRoles.php - About 1 hr to fix

          Method delete has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function delete(): bool
              {
                  global $gCurrentSession, $gL10n;
          
                  $rolId = (int)$this->getValue('rol_id');
          Severity: Minor
          Found in adm_program/system/classes/TableRoles.php - About 1 hr to fix

            Consider simplifying this complex logical expression.
            Open

                            if ($startDate < $row['mem_end'] && $endDate >= $row['mem_end']) {
                                // new period starts in existing period and ends after existing period
                                if ($leader === (bool)$row['mem_leader']) {
                                    $newMembershipSaved = true;
            
            
            Severity: Critical
            Found in adm_program/system/classes/TableRoles.php - About 1 hr to fix

              Function allowedToAssignMembers has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function allowedToAssignMembers(User $user): bool
                  {
                      // you aren't allowed to change membership of not active roles
                      if ((int)$this->getValue('rol_valid') === 0) {
                          return false;
              Severity: Minor
              Found in adm_program/system/classes/TableRoles.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 setMembership has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  public function setMembership(int $userId, string $startDate, string $endDate, ?bool $leader = null, bool $forcePeriod = false)
              Severity: Minor
              Found in adm_program/system/classes/TableRoles.php - About 35 mins to fix

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

                    public function delete(): bool
                    {
                        global $gCurrentSession, $gL10n;
                
                        $rolId = (int)$this->getValue('rol_id');
                Severity: Minor
                Found in adm_program/system/classes/TableRoles.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

                There are no issues that match your filters.

                Category
                Status