propelorm/Propel2

View on GitHub
src/Propel/Generator/Builder/Om/TableMapBuilder.php

Summary

Maintainability
F
1 wk
Test Coverage

File TableMapBuilder.php has 940 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
 * MIT License. This file is part of the Propel package.
 * For the full copyright and license information, please view the LICENSE
Severity: Major
Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 2 days to fix

    TableMapBuilder has 42 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class TableMapBuilder extends AbstractOMBuilder
    {
        /**
         * Gets the package for the map builder classes.
         *
    Severity: Minor
    Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 5 hrs to fix

      Function addInitialize has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function addInitialize(string &$script): void
          {
              $table = $this->getTable();
              /** @var \Propel\Generator\Platform\DefaultPlatform $platform */
              $platform = $this->getPlatform();
      Severity: Minor
      Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 5 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

      Method addInitialize has 77 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function addInitialize(string &$script): void
          {
              $table = $this->getTable();
              /** @var \Propel\Generator\Platform\DefaultPlatform $platform */
              $platform = $this->getPlatform();
      Severity: Major
      Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 3 hrs to fix

        Function addGetPrimaryKeyFromRow has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function addGetPrimaryKeyFromRow(string &$script): void
            {
                $script .= "
            /**
             * Retrieves the primary key from the DB resultset row
        Severity: Minor
        Found in src/Propel/Generator/Builder/Om/TableMapBuilder.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

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

            protected function addDoDelete(string &$script): void
            {
                $table = $this->getTable();
                $script .= "
            /**
        Severity: Major
        Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 2 hrs to fix

          Method addDoInsert has 52 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function addDoInsert(string &$script): void
              {
                  $table = $this->getTable();
                  $tableMapClass = $this->getTableMapClass();
          
          
          Severity: Major
          Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 2 hrs to fix

            Function addDoDelete has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function addDoDelete(string &$script): void
                {
                    $table = $this->getTable();
                    $script .= "
                /**
            Severity: Minor
            Found in src/Propel/Generator/Builder/Om/TableMapBuilder.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 addClassBody has 45 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function addClassBody(string &$script): void
                {
                    $table = $this->getTable();
            
                    $this->declareClasses(
            Severity: Minor
            Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 1 hr to fix

              Method addGetPrimaryKeyFromRow has 44 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function addGetPrimaryKeyFromRow(string &$script): void
                  {
                      $script .= "
                  /**
                   * Retrieves the primary key from the DB resultset row
              Severity: Minor
              Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 1 hr to fix

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

                    protected function addGetOMClassInheritance(string &$script): void
                    {
                        $col = $this->getTable()->getChildrenColumn();
                        $script .= "
                    /**
                Severity: Minor
                Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 1 hr to fix

                  Method addFieldsAttributes has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      protected function addFieldsAttributes(): string
                      {
                          $tableColumns = $this->getTable()->getColumns();
                  
                          $fieldNamesPhpName = '';
                  Severity: Minor
                  Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 1 hr to fix

                    Method addBuildRelations has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        protected function addBuildRelations(string &$script): void
                        {
                            $script .= "
                        /**
                         * Build the RelationMap objects for this table relationships
                    Severity: Minor
                    Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 1 hr to fix

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

                          protected function addPopulateObjects(string &$script): void
                          {
                              $table = $this->getTable();
                              $script .= "
                          /**
                      Severity: Minor
                      Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 1 hr to fix

                        Consider simplifying this complex logical expression.
                        Open

                                    if (
                                        $col->isPrimaryKey()
                                        && $col->isAutoIncrement()
                                        && $table->getIdMethod() !== 'none'
                                        && !$table->isAllowPkInsert()
                        Severity: Critical
                        Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 1 hr to fix

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

                              protected function addPopulateObject(string &$script): void
                              {
                                  $table = $this->getTable();
                                  $script .= "
                              /**
                          Severity: Minor
                          Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 1 hr to fix

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

                                protected function addGetPrimaryKeyHash(string &$script): void
                                {
                                    // We have to iterate through all the columns so that we know the offset of the primary
                                    // key columns.
                                    $n = 0;
                            Severity: Minor
                            Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 1 hr to fix

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

                                  public function addInstancePool(): string
                                  {
                                      // No need to override instancePool if the PK is not composite
                                      if (!$this->getTable()->hasCompositePrimaryKey()) {
                                          return '';
                              Severity: Minor
                              Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 1 hr to fix

                                Function addBuildRelations has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    protected function addBuildRelations(string &$script): void
                                    {
                                        $script .= "
                                    /**
                                     * Build the RelationMap objects for this table relationships
                                Severity: Minor
                                Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 45 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 addDoInsert has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    protected function addDoInsert(string &$script): void
                                    {
                                        $table = $this->getTable();
                                        $tableMapClass = $this->getTableMapClass();
                                
                                
                                Severity: Minor
                                Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 45 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 addGetPrimaryKeyHash has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    protected function addGetPrimaryKeyHash(string &$script): void
                                    {
                                        // We have to iterate through all the columns so that we know the offset of the primary
                                        // key columns.
                                        $n = 0;
                                Severity: Minor
                                Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 45 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 addClearRelatedInstancePool has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    public function addClearRelatedInstancePool(): string
                                    {
                                        $table = $this->getTable();
                                        $relatedClassNames = [];
                                
                                
                                Severity: Minor
                                Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php - About 45 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 addValueSetColumnConstants has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    protected function addValueSetColumnConstants(string &$script): void
                                    {
                                        foreach ($this->getTable()->getColumns() as $col) {
                                            if ($col->isValueSetType()) {
                                                $script .= "
                                Severity: Minor
                                Found in src/Propel/Generator/Builder/Om/TableMapBuilder.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 addAddSelectColumns has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    protected function addAddSelectColumns(string &$script): void
                                    {
                                        $script .= "
                                    /**
                                     * Add all the columns needed to create a new object.
                                Severity: Minor
                                Found in src/Propel/Generator/Builder/Om/TableMapBuilder.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 addValueSetColumnAttributes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    protected function addValueSetColumnAttributes(string &$script): void
                                    {
                                        $script .= "
                                    /**
                                     * The enumerated values for this table
                                Severity: Minor
                                Found in src/Propel/Generator/Builder/Om/TableMapBuilder.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 addRemoveSelectColumns has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    protected function addRemoveSelectColumns(string &$script): void
                                    {
                                        $script .= "
                                    /**
                                     * Remove all the columns needed to create a new object.
                                Severity: Minor
                                Found in src/Propel/Generator/Builder/Om/TableMapBuilder.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

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

                                            if ($col->isPrimaryKey()) {
                                                if ($col->isForeignKey()) {
                                                    foreach ($col->getForeignKeys() as $fk) {
                                                        $script .= "
                                        \$this->addForeignPrimaryKey('$columnName', '$cfc', '" . $col->getType() . "' , '" . $fk->getForeignTableName() . "', '" . $fk->getMappedForeignColumn($col->getName()) . "', " . ($col->isNotNull() ? 'true' : 'false') . ', ' . $size . ", $default);";
                                Severity: Major
                                Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php and 1 other location - About 4 hrs to fix
                                src/Propel/Generator/Builder/Om/TableMapBuilder.php on lines 584..594

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

                                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

                                            } else {
                                                if ($col->isForeignKey()) {
                                                    foreach ($col->getForeignKeys() as $fk) {
                                                        $script .= "
                                        \$this->addForeignKey('$columnName', '$cfc', '" . $col->getType() . "', '" . $fk->getForeignTableName() . "', '" . $fk->getMappedForeignColumn($col->getName()) . "', " . ($col->isNotNull() ? 'true' : 'false') . ', ' . $size . ", $default);";
                                Severity: Major
                                Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php and 1 other location - About 4 hrs to fix
                                src/Propel/Generator/Builder/Om/TableMapBuilder.php on lines 574..594

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

                                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

                                    protected function addAddSelectColumns(string &$script): void
                                    {
                                        $script .= "
                                    /**
                                     * Add all the columns needed to create a new object.
                                Severity: Major
                                Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php and 1 other location - About 1 hr to fix
                                src/Propel/Generator/Builder/Om/TableMapBuilder.php on lines 1323..1360

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

                                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

                                    protected function addRemoveSelectColumns(string &$script): void
                                    {
                                        $script .= "
                                    /**
                                     * Remove all the columns needed to create a new object.
                                Severity: Major
                                Found in src/Propel/Generator/Builder/Om/TableMapBuilder.php and 1 other location - About 1 hr to fix
                                src/Propel/Generator/Builder/Om/TableMapBuilder.php on lines 1274..1312

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

                                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

                                There are no issues that match your filters.

                                Category
                                Status