APO-Epsilon/apo-website

View on GitHub
backup.php

Summary

Maintainability
B
5 hrs
Test Coverage

Function backup_tables has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

function backup_tables($tables = '*')
{
  include('mysql_access.php');
  //get all of the tables
  if($tables == '*')
Severity: Minor
Found in backup.php - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

function backup_tables($tables = '*')
{
  include('mysql_access.php');
  //get all of the tables
  if($tables == '*')
Severity: Minor
Found in backup.php - About 1 hr to fix

    The function backup_tables() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
    Open

    function backup_tables($tables = '*')
    {
      include('mysql_access.php');
      //get all of the tables
      if($tables == '*')
    Severity: Minor
    Found in backup.php by phpmd

    CyclomaticComplexity

    Since: 0.1

    Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

    Example

    // Cyclomatic Complexity = 11
    class Foo {
    1   public function example() {
    2       if ($a == $b) {
    3           if ($a1 == $b1) {
                    fiddle();
    4           } elseif ($a2 == $b2) {
                    fiddle();
                } else {
                    fiddle();
                }
    5       } elseif ($c == $d) {
    6           while ($c == $d) {
                    fiddle();
                }
    7        } elseif ($e == $f) {
    8           for ($n = 0; $n < $h; $n++) {
                    fiddle();
                }
            } else {
                switch ($z) {
    9               case 1:
                        fiddle();
                        break;
    10              case 2:
                        fiddle();
                        break;
    11              case 3:
                        fiddle();
                        break;
                    default:
                        fiddle();
                        break;
                }
            }
        }
    }

    Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

    Avoid using undefined variables such as '$db' which will lead to PHP notices.
    Open

        $result = $db->querty('SHOW TABLES');
    Severity: Minor
    Found in backup.php by phpmd

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

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

      {
        $tables = is_array($tables) ? $tables : explode(',',$tables);
      }
    Severity: Minor
    Found in backup.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

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

              if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
    Severity: Minor
    Found in backup.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 local variables such as '$db'.
    Open

        $result = $db->querty('SHOW TABLES');
    Severity: Minor
    Found in backup.php by phpmd

    UnusedLocalVariable

    Since: 0.2

    Detects when a local variable is declared and/or assigned, but not used.

    Example

    class Foo {
        public function doSomething()
        {
            $i = 5; // Unused
        }
    }

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

    Each PHP statement must be on a line by itself
    Open

              if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

        $tables = array();
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected 12 spaces, found 6
    Open

          while($row = mysql_fetch_row($result))
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 4 spaces, found 2
    Open

      include('mysql_access.php');
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        while($row = mysql_fetch_row($result))
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 5
    Open

        while($row = mysql_fetch_row($result))
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Expected 1 space after ELSE keyword; newline found
    Open

      else
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 4 spaces, found 2
    Open

      {
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 4 spaces, found 2
    Open

      {
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 9
    Open

            for($j=0; $j<$num_fields; $j++)
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 3
    Open

      foreach($tables as $table)
    Severity: Minor
    Found in backup.php by phpcodesniffer

    No space found after comma in function call
    Open

              $row[$j] = ereg_replace("\n","\\n",$row[$j]);
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Expected 1 space after FOREACH keyword; 0 found
    Open

      foreach($tables as $table)
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected 16 spaces, found 8
    Open

            for($j=0; $j<$num_fields; $j++)
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 20 spaces, found 10
    Open

              $row[$j] = ereg_replace("\n","\\n",$row[$j]);
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      foreach($tables as $table)
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

        $return.= 'DROP TABLE '.$table.';';
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 4 spaces, found 2
    Open

      {
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 5
    Open

        for ($i = 0; $i < $num_fields; $i++)
    Severity: Minor
    Found in backup.php by phpcodesniffer

    No space found after comma in function call
    Open

        $tables = is_array($tables) ? $tables : explode(',',$tables);
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 12 spaces, found 6
    Open

          {
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 3
    Open

      if($tables == '*')
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        }
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

        $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Expected 1 space after IF keyword; 0 found
    Open

      if($tables == '*')
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 7
    Open

          while($row = mysql_fetch_row($result))
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 16 spaces, found 8
    Open

            {
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 20 spaces, found 10
    Open

              $row[$j] = addslashes($row[$j]);
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      if($tables == '*')
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

        {
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

        $return.= "\n\n".$row2[1].";\n\n";
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected 20 spaces, found 10
    Open

              if ($j<($num_fields-1)) { $return.= ','; }
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

        $result = $db->querty('SHOW TABLES');
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

        {
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Expected 1 space after WHILE keyword; 0 found
    Open

          while($row = mysql_fetch_row($result))
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 16 spaces, found 8
    Open

            $return.= 'INSERT INTO '.$table.' VALUES(';
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Expected 1 space after FOR keyword; 0 found
    Open

            for($j=0; $j<$num_fields; $j++)
    Severity: Minor
    Found in backup.php by phpcodesniffer

    No space found after comma in function call
    Open

              $row[$j] = ereg_replace("\n","\\n",$row[$j]);
    Severity: Minor
    Found in backup.php by phpcodesniffer

    No space found after comma in function call
    Open

      $handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 4 spaces, found 2
    Open

      fclose($handle);
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      else
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

        $num_fields = mysql_num_fields($result);
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected 20 spaces, found 10
    Open

              if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected 16 spaces, found 8
    Open

            }
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

        $return.="\n\n\n";
    Severity: Minor
    Found in backup.php by phpcodesniffer

    No space found after comma in function call
    Open

      fwrite($handle,$return);
    Severity: Minor
    Found in backup.php by phpcodesniffer

    A closing tag is not permitted at the end of a PHP file
    Open

    ?>
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Newline required after opening brace
    Open

              if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
    Severity: Minor
    Found in backup.php by phpcodesniffer

    No space found after comma in function call
    Open

      $handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Expected 1 space after closing brace; newline found
    Open

      }
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

        $tables = is_array($tables) ? $tables : explode(',',$tables);
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

        $result = mysql_query('SELECT * FROM '.$table);
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Closing brace must be on a line by itself
    Open

              if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Closing brace must be on a line by itself
    Open

              if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Closing brace must be on a line by itself
    Open

              if ($j<($num_fields-1)) { $return.= ','; }
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 4 spaces, found 2
    Open

      fwrite($handle,$return);
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Expected 1 space after WHILE keyword; 0 found
    Open

        while($row = mysql_fetch_row($result))
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 12 spaces, found 6
    Open

          $tables[] = $row[0];
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        for ($i = 0; $i < $num_fields; $i++)
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected 12 spaces, found 6
    Open

          }
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 4 spaces, found 2
    Open

      $handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        }
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Newline required after opening brace
    Open

              if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Newline required after opening brace
    Open

              if ($j<($num_fields-1)) { $return.= ','; }
    Severity: Minor
    Found in backup.php by phpcodesniffer

    Line indented incorrectly; expected at least 16 spaces, found 8
    Open

            $return.= ");\n";
    Severity: Minor
    Found in backup.php by phpcodesniffer

    The variable $num_fields is not named in camelCase.
    Open

    function backup_tables($tables = '*')
    {
      include('mysql_access.php');
      //get all of the tables
      if($tables == '*')
    Severity: Minor
    Found in backup.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $num_fields is not named in camelCase.
    Open

    function backup_tables($tables = '*')
    {
      include('mysql_access.php');
      //get all of the tables
      if($tables == '*')
    Severity: Minor
    Found in backup.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $num_fields is not named in camelCase.
    Open

    function backup_tables($tables = '*')
    {
      include('mysql_access.php');
      //get all of the tables
      if($tables == '*')
    Severity: Minor
    Found in backup.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $num_fields is not named in camelCase.
    Open

    function backup_tables($tables = '*')
    {
      include('mysql_access.php');
      //get all of the tables
      if($tables == '*')
    Severity: Minor
    Found in backup.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    There are no issues that match your filters.

    Category
    Status