modxcms/revolution

View on GitHub
core/xpdo/om/sqlite/xpdomanager.class.php

Summary

Maintainability
F
5 days
Test Coverage

Function createObjectContainer has a Cognitive Complexity of 71 (exceeds 5 allowed). Consider refactoring.
Open

    public function createObjectContainer($className) {
        $created= false;
        if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
            $instance= $this->xpdo->newObject($className);
            if ($instance) {
Severity: Minor
Found in core/xpdo/om/sqlite/xpdomanager.class.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 createObjectContainer has 78 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function createObjectContainer($className) {
        $created= false;
        if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
            $instance= $this->xpdo->newObject($className);
            if ($instance) {
Severity: Major
Found in core/xpdo/om/sqlite/xpdomanager.class.php - About 3 hrs to fix

    File xpdomanager.class.php has 282 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    /*
     * Copyright 2010-2015 by MODX, LLC.
     *
     * This file is part of xPDO.
    Severity: Minor
    Found in core/xpdo/om/sqlite/xpdomanager.class.php - About 2 hrs to fix

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

          public function addField($class, $name, array $options = array()) {
              $result = false;
              if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
                  $className = $this->xpdo->loadClass($class);
                  if ($className) {
      Severity: Minor
      Found in core/xpdo/om/sqlite/xpdomanager.class.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

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

          public function addIndex($class, $name, array $options = array()) {
              $result = false;
              if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
                  $className = $this->xpdo->loadClass($class);
                  if ($className) {
      Severity: Minor
      Found in core/xpdo/om/sqlite/xpdomanager.class.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

      Function removeSourceContainer has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          public function removeSourceContainer($dsnArray = null, $username= null, $password= null) {
              $removed= false;
              if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
                  if ($dsnArray === null) $dsnArray = xPDO::parseDSN($this->xpdo->getOption('dsn'));
                  if (is_array($dsnArray)) {
      Severity: Minor
      Found in core/xpdo/om/sqlite/xpdomanager.class.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

      Function getColumnDef has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function getColumnDef($class, $name, $meta, array $options = array()) {
              $pk = $this->xpdo->getPK($class);
              $pktype = $this->xpdo->getPKType($class);
              $dbtype= strtoupper($meta['dbtype']);
              $precision= isset ($meta['precision']) && !preg_match('/ENUM/i', $dbtype) ? '(' . $meta['precision'] . ')' : '';
      Severity: Minor
      Found in core/xpdo/om/sqlite/xpdomanager.class.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 getColumnDef has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function getColumnDef($class, $name, $meta, array $options = array()) {
              $pk = $this->xpdo->getPK($class);
              $pktype = $this->xpdo->getPKType($class);
              $dbtype= strtoupper($meta['dbtype']);
              $precision= isset ($meta['precision']) && !preg_match('/ENUM/i', $dbtype) ? '(' . $meta['precision'] . ')' : '';
      Severity: Minor
      Found in core/xpdo/om/sqlite/xpdomanager.class.php - About 1 hr to fix

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

            public function createSourceContainer($dsnArray = null, $username= null, $password= null, $containerOptions= array ()) {
                $created = false;
                if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
                    $this->xpdo->log(xPDO::LOG_LEVEL_WARN, 'SQLite does not support source container creation');
                    if ($dsnArray === null) $dsnArray = xPDO::parseDSN($this->xpdo->getOption('dsn'));
        Severity: Minor
        Found in core/xpdo/om/sqlite/xpdomanager.class.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

        Avoid deeply nested control flow statements.
        Open

                                    if (!empty($indexset)) {
                                        switch ($indexType) {
                                            case 'UNIQUE':
                                                $createIndices[$indexkey] = "CREATE UNIQUE INDEX {$this->xpdo->escape($indexkey)} ON {$tableName} ({$indexset})";
                                                break;
        Severity: Major
        Found in core/xpdo/om/sqlite/xpdomanager.class.php - About 45 mins to fix

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

              public function removeObjectContainer($className) {
                  $removed= false;
                  if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
                      $instance= $this->xpdo->newObject($className);
                      if ($instance) {
          Severity: Minor
          Found in core/xpdo/om/sqlite/xpdomanager.class.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

          Consider simplifying this complex logical expression.
          Open

                  if (isset ($meta['index']) && $meta['index'] == 'pk' && !is_array($pk) && $pktype == 'integer' && isset ($meta['generated']) && $meta['generated'] == 'native') {
                      $extra= ' PRIMARY KEY AUTOINCREMENT';
                      $options['nativeGen'] = true;
                      $null= '';
                  }
          Severity: Major
          Found in core/xpdo/om/sqlite/xpdomanager.class.php - About 40 mins to fix

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

                public function removeIndex($class, $name, array $options = array()) {
                    $result = false;
                    if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
                        $className = $this->xpdo->loadClass($class);
                        if ($className) {
            Severity: Minor
            Found in core/xpdo/om/sqlite/xpdomanager.class.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

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

                            if ($created === true && !empty($createIndices)) {
                                foreach ($createIndices as $createIndexKey => $createIndex) {
                                    $indexCreated = $this->xpdo->exec($createIndex);
                                    if ($indexCreated === false && $this->xpdo->errorCode() !== '' && $this->xpdo->errorCode() !== PDO::ERR_NONE) {
                                        $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not create index {$createIndexKey}: {$createIndex} " . print_r($this->xpdo->errorInfo(), true));
            Severity: Major
            Found in core/xpdo/om/sqlite/xpdomanager.class.php and 1 other location - About 3 hrs to fix
            core/xpdo/om/sqlsrv/xpdomanager.class.php on lines 178..187

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

            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

            Identical blocks of code found in 3 locations. Consider refactoring.
            Open

                            if ($created === false && $this->xpdo->errorCode() !== '' && $this->xpdo->errorCode() !== PDO::ERR_NONE) {
                                $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not create table ' . $tableName . "\nSQL: {$sql}\nERROR: " . print_r($this->xpdo->errorInfo(), true));
                            } else {
                                $created= true;
                                $this->xpdo->log(xPDO::LOG_LEVEL_INFO, 'Created table ' . $tableName . "\nSQL: {$sql}\n");
            Severity: Major
            Found in core/xpdo/om/sqlite/xpdomanager.class.php and 2 other locations - About 2 hrs to fix
            core/xpdo/om/mysql/xpdomanager.class.php on lines 255..260
            core/xpdo/om/sqlsrv/xpdomanager.class.php on lines 172..177

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

            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

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

                protected function getIndexDef($class, $name, $meta, array $options = array()) {
                    $result = '';
                    $index = isset($meta['columns']) ? $meta['columns'] : null;
                    if (is_array($index)) {
                        $indexset= array ();
            Severity: Major
            Found in core/xpdo/om/sqlite/xpdomanager.class.php and 1 other location - About 2 hrs to fix
            core/xpdo/om/sqlsrv/xpdomanager.class.php on lines 425..437

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

            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

            Identical blocks of code found in 3 locations. Consider refactoring.
            Open

                    if (strpos(strtolower($attributes), 'unsigned') !== false) {
                        $result = $this->xpdo->escape($name) . ' ' . $dbtype . $precision . $attributes . $null . $default . $extra;
                    } else {
                        $result = $this->xpdo->escape($name) . ' ' . $dbtype . $precision . $null . $default . $attributes . $extra;
                    }
            Severity: Major
            Found in core/xpdo/om/sqlite/xpdomanager.class.php and 2 other locations - About 1 hr to fix
            core/xpdo/om/mysql/xpdomanager.class.php on lines 449..453
            core/xpdo/om/sqlsrv/xpdomanager.class.php on lines 417..421

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

            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