iranianpep/code-jetter

View on GitHub
core/BaseMapper.php

Summary

Maintainability
F
3 days
Test Coverage

File BaseMapper.php has 450 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace CodeJetter\core;

use CodeJetter\core\database\QueryMaker;
Severity: Minor
Found in core/BaseMapper.php - About 6 hrs to fix

    BaseMapper has 36 functions (exceeds 20 allowed). Consider refactoring.
    Open

    abstract class BaseMapper extends Base implements ICrud
    {
        protected $database;
        protected $table;
        protected $modelName;
    Severity: Minor
    Found in core/BaseMapper.php - About 4 hrs to fix

      The class BaseMapper has an overall complexity of 84 which is very high. The configured complexity threshold is 50.
      Open

      abstract class BaseMapper extends Base implements ICrud
      {
          protected $database;
          protected $table;
          protected $modelName;
      Severity: Minor
      Found in core/BaseMapper.php by phpmd

      The class BaseMapper has 13 public methods. Consider refactoring BaseMapper to keep number of public methods under 10.
      Open

      abstract class BaseMapper extends Base implements ICrud
      {
          protected $database;
          protected $table;
          protected $modelName;
      Severity: Minor
      Found in core/BaseMapper.php by phpmd

      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 getOneById has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getOneById($id, $excludeArchived = true)
          {
              $output = new Output();
              /*
               * start validating
      Severity: Minor
      Found in core/BaseMapper.php - About 1 hr to fix

        Method getAll has 8 arguments (exceeds 4 allowed). Consider refactoring.
        Open

                array $criteria = [],
                array $fromColumns = [],
                $order = null,
                $start = 0,
                $limit = 0,
        Severity: Major
        Found in core/BaseMapper.php - About 1 hr to fix

          Function removeTablePrefixAndSuffix has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              public function removeTablePrefixAndSuffix($tableName = null, $tablePrefix = null, $tableSuffix = null)
              {
                  if (empty(trim($tableName))) {
                      $tableName = $this->getTable();
                  }
          Severity: Minor
          Found in core/BaseMapper.php - About 55 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

          Method update has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

                  array $criteria,
                  array $inputs,
                  array $fieldsValues,
                  $limit = 0,
                  $extraDefinedInputs = [],
          Severity: Major
          Found in core/BaseMapper.php - About 50 mins to fix

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

                private function mapRowToObject(array $row, array $tables = [])
                {
                    /**
                     * Initialize $mappedObject.
                     */
            Severity: Minor
            Found in core/BaseMapper.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 mapRowsToObjects has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public function mapRowsToObjects(array $rows, array $tables = [])
                {
                    /**
                     * Initialize $mappedObjects.
                     */
            Severity: Minor
            Found in core/BaseMapper.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

            Missing class import via use statement (line '219', column '18').
            Open

                        (new \CodeJetter\core\ErrorHandler())->logError($e);
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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

            The method getOne has a boolean flag argument $excludeArchived, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function getOne(array $criteria = [], array $fromColumns = [], $excludeArchived = true)
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

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

            The method getOneById has a boolean flag argument $excludeArchived, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function getOneById($id, $excludeArchived = true)
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

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

            Missing class import via use statement (line '458', column '18').
            Open

                        (new \CodeJetter\core\ErrorHandler())->logError($e);
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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 '528', column '27').
            Open

                            throw new \Exception('Connection must be an instance of PDO class');
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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 '648', column '18').
            Open

                        (new \CodeJetter\core\ErrorHandler())->logError($e);
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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 '404', column '27').
            Open

                            throw new \Exception('Connection must be an instance of PDO class');
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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 '615', column '18').
            Open

                        (new \CodeJetter\core\ErrorHandler())->logError($e);
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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 '299', column '18').
            Open

                        (new \CodeJetter\core\ErrorHandler())->logError($e);
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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

            The method updateOne has a boolean flag argument $excludeArchived, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function updateOne(array $criteria, array $fieldsValues, $excludeArchived = true)
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

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

            The method update has a boolean flag argument $excludeArchived, which is a certain sign of a Single Responsibility Principle violation.
            Open

                    $excludeArchived = true,
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

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

            Missing class import via use statement (line '544', column '18').
            Open

                        (new \CodeJetter\core\ErrorHandler())->logError($e);
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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

            The method getModelName has a boolean flag argument $fullPath, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function getModelName($fullPath = true)
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

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

            Missing class import via use statement (line '870', column '27').
            Open

                            throw new \Exception('Class must be specified for a table to map a row to its object');
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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

            The method getAll has a boolean flag argument $excludeArchived, which is a certain sign of a Single Responsibility Principle violation.
            Open

                    $excludeArchived = true,
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

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

            Missing class import via use statement (line '421', column '18').
            Open

                        (new \CodeJetter\core\ErrorHandler())->logError($e);
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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

            The method update has a boolean flag argument $batchAction, which is a certain sign of a Single Responsibility Principle violation.
            Open

                    $batchAction = false
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

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

            Missing class import via use statement (line '238', column '18').
            Open

                        (new \CodeJetter\core\ErrorHandler())->logError($e);
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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 '477', column '27').
            Open

                            throw new \Exception('Connection must be an instance of PDO class');
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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 '440', column '27').
            Open

                            throw new \Exception('Connection must be an instance of PDO class');
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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 '495', column '18').
            Open

                        (new \CodeJetter\core\ErrorHandler())->logError($e);
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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 '351', column '18').
            Open

                        (new \CodeJetter\core\ErrorHandler())->logError($e);
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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

            The method countByCriteria has a boolean flag argument $excludeArchived, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function countByCriteria(array $criteria, $excludeArchived = true)
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

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

            The method getAll has a boolean flag argument $returnTotalNo, which is a certain sign of a Single Responsibility Principle violation.
            Open

                    $returnTotalNo = false,
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

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

            Missing class import via use statement (line '688', column '23').
            Open

                        throw new \Exception('Table name has not been specified for this mapper');
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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

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

                        } else {
                            $result = $statement->fetchAll($fetchStyle);
                        }
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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

            Avoid unused parameters such as '$inputs'.
            Open

                    array $inputs,
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            UnusedFormalParameter

            Since: 0.2

            Avoid passing parameters to methods or constructors and then not using those parameters.

            Example

            class Foo
            {
                private function bar($howdy)
                {
                    // $howdy is not used
                }
            }

            Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

            Avoid unused parameters such as '$extraDefinedInputs'.
            Open

                    $extraDefinedInputs = [],
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            UnusedFormalParameter

            Since: 0.2

            Avoid passing parameters to methods or constructors and then not using those parameters.

            Example

            class Foo
            {
                private function bar($howdy)
                {
                    // $howdy is not used
                }
            }

            Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

            Avoid unused parameters such as '$batchAction'.
            Open

                    $batchAction = false
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            UnusedFormalParameter

            Since: 0.2

            Avoid passing parameters to methods or constructors and then not using those parameters.

            Example

            class Foo
            {
                private function bar($howdy)
                {
                    // $howdy is not used
                }
            }

            Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

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

                public function insertOne(array $fieldsValues)
                {
                    // generate the query
                    $query = (new QueryMaker($this->getTable()))->insertQuery($fieldsValues);
            
            
            Severity: Major
            Found in core/BaseMapper.php and 1 other location - About 5 hrs to fix
            core/BaseMapper.php on lines 469..497

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

            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 batchInsert(array $fieldsValuesCollection)
                {
                    // generate the query
                    $query = (new QueryMaker($this->getTable()))->batchInsertQuery($fieldsValuesCollection);
            
            
            Severity: Major
            Found in core/BaseMapper.php and 1 other location - About 5 hrs to fix
            core/BaseMapper.php on lines 432..460

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

            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

            Avoid excessively long variable names like $fieldsValuesCollection. Keep variable name length under 20.
            Open

                public function batchInsert(array $fieldsValuesCollection)
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            LongVariable

            Since: 0.2

            Detects when a field, formal or local variable is declared with a long name.

            Example

            class Something {
                protected $reallyLongIntName = -3; // VIOLATION - Field
                public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                    $otherReallyLongName = -5; // VIOLATION - Local
                    for ($interestingIntIndex = 0; // VIOLATION - For
                         $interestingIntIndex < 10;
                         $interestingIntIndex++ ) {
                    }
                }
            }

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

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

                public function getOneById($id, $excludeArchived = true)
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            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 'getEnumValues()' method which returns a boolean should be named 'is...()' or 'has...()'
            Open

                public function getEnumValues($column)
                {
                    return (new MysqlUtility())->getEnumValues($column, $this->getTable(), $this->getDatabase());
                }
            Severity: Minor
            Found in core/BaseMapper.php by phpmd

            BooleanGetMethodName

            Since: 0.2

            Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.

            Example

            class Foo {
                /**
                 * @return boolean
                 */
                public function getFoo() {} // bad
                /**
                 * @return bool
                 */
                public function isFoo(); // ok
                /**
                 * @return boolean
                 */
                public function getFoo($bar); // ok, unless checkParameterizedMethods=true
            }

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

            There are no issues that match your filters.

            Category
            Status