wikimedia/mediawiki-core

View on GitHub
includes/libs/rdbms/database/DatabasePostgres.php

Summary

Maintainability
F
5 days
Test Coverage

File DatabasePostgres.php has 789 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
Severity: Major
Found in includes/libs/rdbms/database/DatabasePostgres.php - About 1 day to fix

    DatabasePostgres has 56 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class DatabasePostgres extends Database {
        /** @var int */
        private $port;
        /** @var string */
        private $tempSchema;
    Severity: Major
    Found in includes/libs/rdbms/database/DatabasePostgres.php - About 1 day to fix

      Method indexAttributes has 55 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function indexAttributes( $index, $schema = false ) {
              if ( $schema === false ) {
                  $schemas = $this->getCoreSchemas();
              } else {
                  $schemas = [ $schema ];
      Severity: Major
      Found in includes/libs/rdbms/database/DatabasePostgres.php - About 2 hrs to fix

        Method open has 54 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function open( $server, $user, $password, $db, $schema, $tablePrefix ) {
                if ( !function_exists( 'pg_connect' ) ) {
                    throw $this->newExceptionAfterConnectError(
                        "Postgres functions missing, have you compiled PHP with the --with-pgsql\n" .
                        "option? (Note: if you recently installed PHP, you may need to restart your\n" .
        Severity: Major
        Found in includes/libs/rdbms/database/DatabasePostgres.php - About 2 hrs to fix

          Method duplicateTableStructure has 51 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function duplicateTableStructure(
                  $oldName, $newName, $temporary = false, $fname = __METHOD__
              ) {
                  $newNameE = $this->platform->addIdentifierQuotes( $newName );
                  $oldNameE = $this->platform->addIdentifierQuotes( $oldName );
          Severity: Major
          Found in includes/libs/rdbms/database/DatabasePostgres.php - About 2 hrs to fix

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

                protected function getInsertIdColumnForUpsert( $table ) {
                    $column = null;
            
                    $flags = self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE;
                    $encTable = $this->addQuotes( $this->tableName( $table, 'raw' ) );
            Severity: Minor
            Found in includes/libs/rdbms/database/DatabasePostgres.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

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

                protected function open( $server, $user, $password, $db, $schema, $tablePrefix ) {
                    if ( !function_exists( 'pg_connect' ) ) {
                        throw $this->newExceptionAfterConnectError(
                            "Postgres functions missing, have you compiled PHP with the --with-pgsql\n" .
                            "option? (Note: if you recently installed PHP, you may need to restart your\n" .
            Severity: Minor
            Found in includes/libs/rdbms/database/DatabasePostgres.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 getInsertIdColumnForUpsert has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function getInsertIdColumnForUpsert( $table ) {
                    $column = null;
            
                    $flags = self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE;
                    $encTable = $this->addQuotes( $this->tableName( $table, 'raw' ) );
            Severity: Minor
            Found in includes/libs/rdbms/database/DatabasePostgres.php - About 1 hr to fix

              Method relationExists has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function relationExists( $table, $types, $schema = false ) {
                      if ( !is_array( $types ) ) {
                          $types = [ $types ];
                      }
                      if ( $schema === false ) {
              Severity: Minor
              Found in includes/libs/rdbms/database/DatabasePostgres.php - About 1 hr to fix

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

                        $destTable,
                        $srcTable,
                        array $varMap,
                        $conds,
                        $fname,
                Severity: Major
                Found in includes/libs/rdbms/database/DatabasePostgres.php - About 1 hr to fix

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

                      public function indexAttributes( $index, $schema = false ) {
                          if ( $schema === false ) {
                              $schemas = $this->getCoreSchemas();
                          } else {
                              $schemas = [ $schema ];
                  Severity: Minor
                  Found in includes/libs/rdbms/database/DatabasePostgres.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 addQuotes has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function addQuotes( $s ) {
                          $conn = $this->getBindingHandle();
                  
                          if ( $s === null ) {
                              return 'NULL';
                  Severity: Minor
                  Found in includes/libs/rdbms/database/DatabasePostgres.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

                  Method estimateRowCount has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      public function estimateRowCount( $table, $var = '*', $conds = '',
                          $fname = __METHOD__, $options = [], $join_conds = []
                  Severity: Minor
                  Found in includes/libs/rdbms/database/DatabasePostgres.php - About 45 mins to fix

                    Method open has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        protected function open( $server, $user, $password, $db, $schema, $tablePrefix ) {
                    Severity: Minor
                    Found in includes/libs/rdbms/database/DatabasePostgres.php - About 45 mins to fix

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

                          public function getValueTypesForWithClause( $table ) {
                              $typesByColumn = [];
                      
                              $flags = self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE;
                              $encTable = $this->addQuotes( $table );
                      Severity: Minor
                      Found in includes/libs/rdbms/database/DatabasePostgres.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

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

                          private function relationExists( $table, $types, $schema = false ) {
                              if ( !is_array( $types ) ) {
                                  $types = [ $types ];
                              }
                              if ( $schema === false ) {
                      Severity: Minor
                      Found in includes/libs/rdbms/database/DatabasePostgres.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 'DEFAULT';
                      Severity: Major
                      Found in includes/libs/rdbms/database/DatabasePostgres.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                return "'" . pg_escape_string( $conn, (string)$s ) . "'";
                        Severity: Major
                        Found in includes/libs/rdbms/database/DatabasePostgres.php - About 30 mins to fix

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

                              private function pg_array_parse( $text, &$output, $limit = false, $offset = 1 ) {
                                  if ( $limit === false ) {
                                      $limit = strlen( $text ) - 1;
                                      $output = [];
                                  }
                          Severity: Minor
                          Found in includes/libs/rdbms/database/DatabasePostgres.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 determineCoreSchema has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              public function determineCoreSchema( $desiredSchema ) {
                                  if ( $this->trxLevel() ) {
                                      // We do not want the schema selection to change on ROLLBACK or INSERT SELECT.
                                      // See https://www.postgresql.org/docs/8.3/sql-set.html
                                      throw new DBUnexpectedError(
                          Severity: Minor
                          Found in includes/libs/rdbms/database/DatabasePostgres.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