piotrpolak/pepiscms

View on GitHub
pepiscms/modules/crud/libraries/TableUtility.php

Summary

Maintainability
F
3 days
Test Coverage

Function getDefinitionFromTable has a Cognitive Complexity of 53 (exceeds 5 allowed). Consider refactoring.
Open

    public function getDefinitionFromTable($table, $resolve_fk = true)
    {
        $collumns_a = $this->getTableRawDescription($table);
        if (!$collumns_a) {
            return false;
Severity: Minor
Found in pepiscms/modules/crud/libraries/TableUtility.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

Method getDefinitionFromTable has 103 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getDefinitionFromTable($table, $resolve_fk = true)
    {
        $collumns_a = $this->getTableRawDescription($table);
        if (!$collumns_a) {
            return false;
Severity: Major
Found in pepiscms/modules/crud/libraries/TableUtility.php - About 4 hrs to fix

    File TableUtility.php has 320 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    /**
     * PepisCMS
     *
    Severity: Minor
    Found in pepiscms/modules/crud/libraries/TableUtility.php - About 3 hrs to fix

      Function getManyToManyRelationshipsRelatedToTable has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getManyToManyRelationshipsRelatedToTable($table)
          {
              $related_foreign_keys = $this->getForeignKeysRelatedToTable($table);
      
              $many_to_many_fks = array();
      Severity: Minor
      Found in pepiscms/modules/crud/libraries/TableUtility.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

      Consider simplifying this complex logical expression.
      Open

                      if (strpos($field_name, 'color') !== false || strpos($field_name, 'colour') !== false) {
                          $input_type = FormBuilder::COLORPICKER;
                      } elseif (strpos($field_name, 'path') !== false || strpos($field_name, 'image') !== false || strpos($field_name, 'file') !== false || strpos($field_name, 'icon') !== false || strpos($field_name, 'logo') !== false || strpos($field_name, 'baner') !== false || strpos($field_name, 'thumb') !== false || strpos($field_name, 'img') !== false) {
                          $input_type = FormBuilder::FILE;
                          $definition[$field_name]['upload_path'] = 'uploads/';
      Severity: Critical
      Found in pepiscms/modules/crud/libraries/TableUtility.php - About 1 hr to fix

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

            public function getTableLabelFieldName($table, $exclude_field_names = array())
            {
                // Try from set of possible labels
                $allowed_labels = array('name', 'label', 'username', 'login', 'fitst_name', 'last_name', 'code', 'id');
                $fk_table_definition = $this->getDefinitionFromTable($table, false);
        Severity: Minor
        Found in pepiscms/modules/crud/libraries/TableUtility.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 getManyToManyRelationshipsRelatedToTable has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function getManyToManyRelationshipsRelatedToTable($table)
            {
                $related_foreign_keys = $this->getForeignKeysRelatedToTable($table);
        
                $many_to_many_fks = array();
        Severity: Minor
        Found in pepiscms/modules/crud/libraries/TableUtility.php - About 1 hr to fix

          Method orderFieldsByImportance has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function orderFieldsByImportance($definition)
              {
                  $order = array(
                      FormBuilder::TEXTFIELD,
                      FormBuilder::PASSWORD,
          Severity: Minor
          Found in pepiscms/modules/crud/libraries/TableUtility.php - About 1 hr to fix

            Function getInputType has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public static function getInputType($type, $field_name)
                {
                    if ($type == 'smallint') {
                        return FormBuilder::CHECKBOX;
                    } elseif (self::isDbTypeNumeric($type)) {
            Severity: Minor
            Found in pepiscms/modules/crud/libraries/TableUtility.php - About 35 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

            Avoid too many return statements within this method.
            Open

                        return FormBuilder::TIMESTAMP;
            Severity: Major
            Found in pepiscms/modules/crud/libraries/TableUtility.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return FormBuilder::PASSWORD;
              Severity: Major
              Found in pepiscms/modules/crud/libraries/TableUtility.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return FormBuilder::TEXTFIELD;
                Severity: Major
                Found in pepiscms/modules/crud/libraries/TableUtility.php - About 30 mins to fix

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

                      public function getForeignKeys()
                      {
                          if ($this->foreign_keys_cache === null) {
                              $query = $this->db_instance->query('SELECT table_name, column_name, referenced_table_name, referenced_column_name from information_schema.key_column_usage where referenced_table_name is not null');
                              $foreign_keys_a = $query->result_array();
                  Severity: Minor
                  Found in pepiscms/modules/crud/libraries/TableUtility.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

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

                      public function getForeignKeysRelatedToTable($table)
                      {
                          $related_foreign_keys = array();
                  
                          $fks = $this->getForeignKeys();
                  Severity: Minor
                  Found in pepiscms/modules/crud/libraries/TableUtility.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