mambax7/publisher

View on GitHub
testdata/index.php

Summary

Maintainability
B
4 hrs
Test Coverage

Function loadTableFromArrayWithReplace has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

function loadTableFromArrayWithReplace($table, $data, $search, $replace)
{
    /** @var \XoopsMySQLDatabase $db */
    $db = \XoopsDatabaseFactory::getDatabaseConnection();

Severity: Minor
Found in testdata/index.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 loadTableFromArrayWithReplace has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function loadTableFromArrayWithReplace($table, $data, $search, $replace)
{
    /** @var \XoopsMySQLDatabase $db */
    $db = \XoopsDatabaseFactory::getDatabaseConnection();

Severity: Minor
Found in testdata/index.php - About 1 hr to fix

    Method loadSampleData has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function loadSampleData()
    {
        global $xoopsConfig;
        $moduleDirName      = \basename(\dirname(__DIR__));
        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
    Severity: Minor
    Found in testdata/index.php - About 1 hr to fix

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

      function loadSampleData()
      {
          global $xoopsConfig;
          $moduleDirName      = \basename(\dirname(__DIR__));
          $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
      Severity: Minor
      Found in testdata/index.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

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

          TableLoad::saveTableToYamlFile('group_permission', $exportFolder . 'group_permission.yml', $criteria, $skipColumns);
      Severity: Minor
      Found in testdata/index.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

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

          $skipColumns[] = 'gperm_id';
      Severity: Minor
      Found in testdata/index.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

      Missing class import via use statement (line '128', column '24').
      Open

          $criteria->add(new \Criteria('gperm_modid', $helper->getModule()->getVar('mid')));
      Severity: Minor
      Found in testdata/index.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 '127', column '21').
      Open

          $criteria = new \CriteriaCompo();
      Severity: Minor
      Found in testdata/index.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

      Avoid using static access to class '\Xmf\Database\TableLoad' in method 'saveSampleData'.
      Open

              TableLoad::saveTableToYamlFile($table, $exportFolder . $table . '.yml');
      Severity: Minor
      Found in testdata/index.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class '\XoopsModules\Publisher\Utility' in method 'saveSampleData'.
      Open

          Utility::createFolder($exportFolder);
      Severity: Minor
      Found in testdata/index.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class '\Xmf\Yaml' in method 'loadSampleData'.
      Open

              $tabledata = Yaml::readWrapped($language . $table . '.yml');
      Severity: Minor
      Found in testdata/index.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class '\Xmf\Database\TableLoad' in method 'saveSampleData'.
      Open

          TableLoad::saveTableToYamlFile('group_permission', $exportFolder . 'group_permission.yml', $criteria, $skipColumns);
      Severity: Minor
      Found in testdata/index.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class '\Xmf\Database\TableLoad' in method 'loadSampleData'.
      Open

              TableLoad::truncateTable($table);
      Severity: Minor
      Found in testdata/index.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class '\Xmf\Database\TableLoad' in method 'clearSampleData'.
      Open

              \Xmf\Database\TableLoad::truncateTable($table);
      Severity: Minor
      Found in testdata/index.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class '\XoopsDatabaseFactory' in method 'loadTableFromArrayWithReplace'.
      Open

          $db = \XoopsDatabaseFactory::getDatabaseConnection();
      Severity: Minor
      Found in testdata/index.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class '\XoopsModules\Publisher\Utility' in method 'saveSampleData'.
      Open

              Utility::createFolder($languageFolder . '/');
      Severity: Minor
      Found in testdata/index.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

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

                  } else {
                      $valueClause .= $db->quote($value);
                  }
      Severity: Minor
      Found in testdata/index.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 using static access to class '\XoopsModules\Publisher\Helper' in method 'clearSampleData'.
      Open

          $helper             = Helper::getInstance();
      Severity: Minor
      Found in testdata/index.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class '\XoopsModules\Publisher\Helper' in method 'saveSampleData'.
      Open

          $helper             = Helper::getInstance();
      Severity: Minor
      Found in testdata/index.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

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

                  } else {
                      $insertInto  .= ', ';
                      $valueClause .= ', ';
                  }
      Severity: Minor
      Found in testdata/index.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 using static access to class '\Xmf\Database\TableLoad' in method 'loadSampleData'.
      Open

              TableLoad::loadTableFromArray($table, $tabledata);
      Severity: Minor
      Found in testdata/index.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class '\Xmf\Yaml' in method 'loadSampleData'.
      Open

          $tabledata = Yaml::readWrapped($language . $table . '.yml');
      Severity: Minor
      Found in testdata/index.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      The function exportSchema() contains an exit expression.
      Open

              exit(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_ERROR'));
      Severity: Minor
      Found in testdata/index.php by phpmd

      ExitExpression

      Since: 0.2

      An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

      Example

      class Foo {
          public function bar($param)  {
              if ($param === 42) {
                  exit(23);
              }
          }
      }

      Source https://phpmd.org/rules/design.html#exitexpression

      TODO found
      Open

              // TODO set exportSchema
      Severity: Minor
      Found in testdata/index.php by fixme

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

          $db = \XoopsDatabaseFactory::getDatabaseConnection();
      Severity: Minor
      Found in testdata/index.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

      A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 65 and the first side effect is on line 30.
      Open

      <?php
      Severity: Minor
      Found in testdata/index.php by phpcodesniffer

      There must be one USE keyword per declaration
      Open

      use XoopsModules\Publisher\{Helper,
      Severity: Minor
      Found in testdata/index.php by phpcodesniffer

      There must be one blank line after the last USE statement; 0 found;
      Open

      use XoopsModules\Publisher\{Helper,
      Severity: Minor
      Found in testdata/index.php by phpcodesniffer

      Opening brace should be on a new line
      Open

      function clearSampleData(){
      Severity: Minor
      Found in testdata/index.php by phpcodesniffer

      There are no issues that match your filters.

      Category
      Status