attogram/attogram-database

View on GitHub

Showing 7,594 of 7,594 total issues

File db-admin.php has 4793 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
// Attogram Framework - Database Module - phpLiteAdmin mod v0.0.5

//
//    Project: phpLiteAdmin (https://bitbucket.org/phpliteadmin/public)
Severity: Major
Found in admin_actions/db-admin.php - About 1 wk to fix

    Function alterTable has a Cognitive Complexity of 273 (exceeds 5 allowed). Consider refactoring.
    Open

        public function alterTable($table, $alterdefs)
        {
            global $debug, $lang;
            $this->alterError="";
            $errormsg = sprintf($lang['alter_failed'],htmlencode($table)).' - ';
    Severity: Minor
    Found in admin_actions/db-admin.php - About 5 days 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(isset($_POST['query']) && $_POST['query']!="")
                {
                    $delimiter = $_POST['delimiter'];
                    $queryStr = $_POST['queryval'];
                    //save the queries in history if necessary
    Severity: Major
    Found in admin_actions/db-admin.php and 1 other location - About 3 days to fix
    admin_actions/db-admin.php on lines 3853..3938

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

    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

            if(isset($_POST['query']) && $_POST['query']!="")
            {
                $delimiter = $_POST['delimiter'];
                $queryStr = $_POST['queryval'];
                //save the queries in history if necessary
    Severity: Major
    Found in admin_actions/db-admin.php and 1 other location - About 3 days to fix
    admin_actions/db-admin.php on lines 1917..2003

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

    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

    Method alterTable has 332 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function alterTable($table, $alterdefs)
        {
            global $debug, $lang;
            $this->alterError="";
            $errormsg = sprintf($lang['alter_failed'],htmlencode($table)).' - ';
    Severity: Major
    Found in admin_actions/db-admin.php - About 1 day to fix

      Function export_sql has a Cognitive Complexity of 70 (exceeds 5 allowed). Consider refactoring.
      Open

          public function export_sql($tables, $drop, $structure, $data, $transaction, $comments)
          {
              global $lang;
              if($comments)
              {
      Severity: Minor
      Found in admin_actions/db-admin.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

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

                          if($_POST[$i.'_defaultoption']!='defined' && $_POST[$i.'_defaultoption']!='none' && $_POST[$i.'_defaultoption']!='expr')
                              $query .= "DEFAULT ".$_POST[$i.'_defaultoption']." ";
                          elseif($_POST[$i.'_defaultoption']=='expr')
                              $query .= "DEFAULT (".$_POST[$i.'_defaultvalue'].") ";
                          elseif(isset($_POST[$i.'_defaultvalue']) && $_POST[$i.'_defaultoption']=='defined')
      Severity: Major
      Found in admin_actions/db-admin.php and 1 other location - About 1 day to fix
      admin_actions/db-admin.php on lines 1462..1473

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

      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

                          if($_POST[$i.'_defaultoption']!='defined' && $_POST[$i.'_defaultoption']!='none' && $_POST[$i.'_defaultoption']!='expr')
                              $query .= "DEFAULT ".$_POST[$i.'_defaultoption']." ";
                          elseif($_POST[$i.'_defaultoption']=='expr')
                              $query .= "DEFAULT (".$_POST[$i.'_defaultvalue'].") ";
                          elseif(isset($_POST[$i.'_defaultvalue']) && $_POST[$i.'_defaultoption']=='defined')
      Severity: Major
      Found in admin_actions/db-admin.php and 1 other location - About 1 day to fix
      admin_actions/db-admin.php on lines 1149..1160

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

      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

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

          public function export_csv($tables, $field_terminate, $field_enclosed, $field_escaped, $null, $crlf, $fields_in_first_row)
          {
              $field_enclosed = $field_enclosed;
              $query = "SELECT * FROM sqlite_master WHERE type='table' or type='view' ORDER BY type DESC";
              $result = $this->selectArray($query);
      Severity: Minor
      Found in admin_actions/db-admin.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

      Function selectArray has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
      Open

          public function selectArray($query, $mode="both")
          {
              $result = $this->query($query);
              //make sure the result is valid
              if($result=== false || $result===NULL)
      Severity: Minor
      Found in admin_actions/db-admin.php - About 6 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 select has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
      Open

          public function select($query, $mode="both")
          {
              $result = $this->query($query);
              if(!$result) //make sure the result is valid
                  return NULL;
      Severity: Minor
      Found in admin_actions/db-admin.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

      Function import_csv has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

          public function import_csv($filename, $table, $field_terminate, $field_enclosed, $field_escaped, $null, $fields_in_first_row)
          {
              // CSV import implemented by Christopher Kramer - http://www.christosoft.de
              $csv_handle = fopen($filename,'r');
              $csv_insert = "BEGIN;\n";
      Severity: Minor
      Found in admin_actions/db-admin.php - About 4 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

      Database has 37 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Database
      {
          protected $db; //reference to the DB object
          protected $type; //the extension for PHP that handles SQLite
          protected $data;
      Severity: Minor
      Found in admin_actions/db-admin.php - About 4 hrs to fix

        Function explode_sql has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
        Open

        function explode_sql($delimiter, $sql)
        {
            $ign = array('"' => '"', "'" => "'", "/*" => "*/", "--" => "\n"); // Ignore sequences.
            $out = array();
            $last = 0;
        Severity: Minor
        Found in admin_actions/db-admin.php - About 4 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

        File SqliteDatabase.php has 323 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        <?php  // Attogram Framework - Database Module - SqliteDatabase class v0.3.20
        
        namespace Attogram;
        
        /**
        Severity: Minor
        Found in includes/SqliteDatabase.php - About 3 hrs to fix

          Method export_sql has 86 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function export_sql($tables, $drop, $structure, $data, $transaction, $comments)
              {
                  global $lang;
                  if($comments)
                  {
          Severity: Major
          Found in admin_actions/db-admin.php - About 3 hrs to fix

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

            class SqliteDatabase implements AttogramDatabaseInterface
            {
            
                public $databaseName;      // (string) path/filename of the SQLite database file
                public $modulesDirectory;  // (string) The Attogram Modules directory
            Severity: Minor
            Found in includes/SqliteDatabase.php by phpmd

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

            class Database
            {
                protected $db; //reference to the DB object
                protected $type; //the extension for PHP that handles SQLite
                protected $data;
            Severity: Minor
            Found in admin_actions/db-admin.php by phpmd

            The class Database has 22 public methods. Consider refactoring Database to keep number of public methods under 10.
            Open

            class Database
            {
                protected $db; //reference to the DB object
                protected $type; //the extension for PHP that handles SQLite
                protected $data;
            Severity: Minor
            Found in admin_actions/db-admin.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

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

                                for($i=0; $i<sizeof($result); $i++)
                                {
                                    if(isset($_SESSION[COOKIENAME.$target_table.'chartvalues']) && $_SESSION[COOKIENAME.$target_table.'chartvalues']==$i)
                                        echo "<option value='".$i."' selected='selected'>".htmlencode($result[$i]['name'])."</option>";
                                    else
            Severity: Major
            Found in admin_actions/db-admin.php and 1 other location - About 2 hrs to fix
            admin_actions/db-admin.php on lines 2777..2783

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

            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

            Severity
            Category
            Status
            Source
            Language