phug-php/tester

View on GitHub
src/Phug/Tester/Coverage.php

Summary

Maintainability
F
4 days
Test Coverage

The method getTemplateFile() contains an eval expression.
Open

        eval("?>$__php");
Severity: Minor
Found in src/Phug/Tester/Coverage.php by phpmd

EvalExpression

Since: 0.2

An eval-expression is untestable, a security risk and bad practice. Therefore it should be avoided. Consider to replace the eval-expression with regular code.

Example

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

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

Function dumpCoverage has a Cognitive Complexity of 94 (exceeds 5 allowed). Consider refactoring.
Open

    public function dumpCoverage(bool $output = false, string $directory = null)
    {
        if ($directory) {
            static::addEmptyDirectory($directory);
            foreach (static::$assets as $asset) {
Severity: Minor
Found in src/Phug/Tester/Coverage.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

File Coverage.php has 412 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Phug\Tester;

use Phug\Ast\NodeInterface as AstNodeInterface;
Severity: Minor
Found in src/Phug/Tester/Coverage.php - About 5 hrs to fix

    Method dumpCoverage has 146 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function dumpCoverage(bool $output = false, string $directory = null)
        {
            if ($directory) {
                static::addEmptyDirectory($directory);
                foreach (static::$assets as $asset) {
    Severity: Major
    Found in src/Phug/Tester/Coverage.php - About 5 hrs to fix

      Coverage has 29 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Coverage
      {
          const VERSION = '0.1.0';
      
          /**
      Severity: Minor
      Found in src/Phug/Tester/Coverage.php - About 3 hrs to fix

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

        class Coverage
        {
            const VERSION = '0.1.0';
        
            /**
        Severity: Minor
        Found in src/Phug/Tester/Coverage.php by phpmd

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

            private function getLocationPath(string $path): string
            {
                foreach ($this->getPaths() as $base) {
                    $realBase = realpath($base);
                    if ($realBase) {
        Severity: Minor
        Found in src/Phug/Tester/Coverage.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 emptyDirectory has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            protected static function emptyDirectory(string $dir)
            {
                if (!is_dir($dir)) {
                    return;
                }
        Severity: Minor
        Found in src/Phug/Tester/Coverage.php - About 55 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 (!($node instanceof DocumentNode) && ($location = $node->getSourceLocation())) {
                                            $locationPath = $location->getPath();
                                            if (!isset($counts[$locationPath])) {
                                                $counts[$locationPath] = $this->countFileNodes($locationPath);
                                            }
        Severity: Major
        Found in src/Phug/Tester/Coverage.php - About 45 mins to fix

          The method dumpCoverage() has an NPath complexity of 3646296. The configured NPath complexity threshold is 200.
          Open

              public function dumpCoverage(bool $output = false, string $directory = null)
              {
                  if ($directory) {
                      static::addEmptyDirectory($directory);
                      foreach (static::$assets as $asset) {
          Severity: Minor
          Found in src/Phug/Tester/Coverage.php by phpmd

          NPathComplexity

          Since: 0.1

          The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

          Example

          class Foo {
              function bar() {
                  // lots of complicated code
              }
          }

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

          The method dumpCoverage() has 153 lines of code. Current threshold is set to 100. Avoid really long methods.
          Open

              public function dumpCoverage(bool $output = false, string $directory = null)
              {
                  if ($directory) {
                      static::addEmptyDirectory($directory);
                      foreach (static::$assets as $asset) {
          Severity: Minor
          Found in src/Phug/Tester/Coverage.php by phpmd

          The method dumpCoverage() has a Cyclomatic Complexity of 38. The configured cyclomatic complexity threshold is 10.
          Open

              public function dumpCoverage(bool $output = false, string $directory = null)
              {
                  if ($directory) {
                      static::addEmptyDirectory($directory);
                      foreach (static::$assets as $asset) {
          Severity: Minor
          Found in src/Phug/Tester/Coverage.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

          Missing class import via use statement (line '185', column '23').
          Open

                      throw new \BadFunctionCallException('You need to install XDebug to use coverage feature.');
          Severity: Minor
          Found in src/Phug/Tester/Coverage.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

          The method dumpCoverage has a boolean flag argument $output, which is a certain sign of a Single Responsibility Principle violation.
          Open

              public function dumpCoverage(bool $output = false, string $directory = null)
          Severity: Minor
          Found in src/Phug/Tester/Coverage.php by phpmd

          BooleanArgumentFlag

          Since: 1.4.0

          A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

          Example

          class Foo {
              public function bar($flag = true) {
              }
          }

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

          Avoid assigning values to variables in if clauses and the like (line '361', column '74').
          Open

              public function dumpCoverage(bool $output = false, string $directory = null)
              {
                  if ($directory) {
                      static::addEmptyDirectory($directory);
                      foreach (static::$assets as $asset) {
          Severity: Minor
          Found in src/Phug/Tester/Coverage.php by phpmd

          IfStatementAssignment

          Since: 2.7.0

          Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

          Example

          class Foo
          {
              public function bar($flag)
              {
                  if ($foo = 'bar') { // possible typo
                      // ...
                  }
                  if ($baz = 0) { // always false
                      // ...
                  }
              }
          }

          Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

          Assigning null to property but \Phug\Tester\Coverage::$singleton is \Phug\Tester\Coverage
          Open

                  static::$singleton = null;
          Severity: Minor
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method getSourceLocation from undeclared class \Phug\Parser\NodeInterface
          Open

                                          if (!($node instanceof DocumentNode) && ($location = $node->getSourceLocation())) {
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Argument 1 (input) is int but \str_pad() takes string
          Open

                          str_pad($coveredNodes, 3, ' ', STR_PAD_LEFT).' / '.
          Severity: Minor
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method getOption from undeclared class \Phug\Renderer
          Open

                  static::removeDirectory($this->renderer->getOption('cache_dir'));
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method getOption from undeclared class \Phug\Renderer
          Open

                  $cache = $this->renderer->getOption('cache_dir');
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method getCompiler from undeclared class \Phug\Renderer
          Open

                  $document = $this->renderer->getCompiler()->getParser()->parse($contents, $file);
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Checking instanceof against undeclared class \Phug\Parser\NodeInterface
          Open

                  if ($node instanceof NodeInterface && !($node instanceof DocumentNode) && !$list->offsetExists($node)) {
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Checking instanceof against undeclared class \Phug\Ast\NodeInterface
          Open

                  if ($node instanceof AstNodeInterface) {
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Argument 1 (input) is int but \str_pad() takes string
          Open

                              str_pad($_nodes, 3, ' ', STR_PAD_LEFT).'   '.
          Severity: Minor
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method getOuterNode from undeclared class \Phug\Parser\NodeInterface
          Open

                                          $node = $node->getOuterNode() ?: $node->getParent()) {
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Checking instanceof against undeclared class \Phug\Parser\Node\DocumentNode
          Open

                                          if (!($node instanceof DocumentNode) && ($location = $node->getSourceLocation())) {
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Parameter $location has undeclared type ?\Phug\Util\SourceLocationInterface
          Open

              protected function recordLocation(SourceLocationInterface $location = null, int $covered = 0)
          Severity: Minor
          Found in src/Phug/Tester/Coverage.php by phan

          Argument 1 (input) is 0|int but \str_pad() takes string
          Open

                              str_pad($_coveredNodes, 3, ' ', STR_PAD_LEFT).' / '.
          Severity: Minor
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method getPath from undeclared class \Phug\Util\SourceLocationInterface
          Open

                      $locationPath = realpath($location->getPath());
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method getOption from undeclared class \Phug\Renderer
          Open

                  return $this->renderer->getOption('paths');
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method scanDirectory from undeclared class \Phug\Renderer
          Open

                      foreach ($this->renderer->scanDirectory($path) as $file) {
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Checking instanceof against undeclared class \Phug\Parser\Node\DocumentNode
          Open

                  if ($node instanceof NodeInterface && !($node instanceof DocumentNode) && !$list->offsetExists($node)) {
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Return type of createRenderer() is undeclared type \Phug\Renderer
          Open

              public function createRenderer($renderer, array $options = []): Renderer
          Severity: Minor
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method getCompiler from undeclared class \Phug\Renderer
          Open

                  $formatter = $this->renderer->getCompiler()->getFormatter();
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method getParent from undeclared class \Phug\Parser\NodeInterface
          Open

                                          $node = $node->getOuterNode() ?: $node->getParent()) {
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Return type of getRenderer() is undeclared type \Phug\Renderer
          Open

              public function getRenderer(): Renderer
          Severity: Minor
          Found in src/Phug/Tester/Coverage.php by phan

          Static property \Phug\Tester\Coverage::$singleton is declared to have type static, but the only instance is shared among all subclasses (Did you mean \Phug\Tester\Coverage)
          Open

               * @var static
          Severity: Info
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method getChildren from undeclared class \Phug\Ast\NodeInterface
          Open

                      foreach ($node->getChildren() as $child) {
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method getCompiler from undeclared class \Phug\Renderer
          Open

                  $compiler = $this->renderer->getCompiler();
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Argument 1 (input) is int but \str_pad() takes string
          Open

                                  str_pad($id, $pad, ' ', STR_PAD_LEFT).
          Severity: Minor
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method getOption from undeclared class \Phug\Renderer
          Open

                  static::emptyDirectory($this->renderer->getOption('cache_dir'));
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method getLine from undeclared class \Phug\Util\SourceLocationInterface
          Open

                      $locationLine = $location->getLine() - 1;
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method getSourceLocation from undeclared class \Phug\Parser\NodeInterface
          Open

                      $this->recordLocation($node->getSourceLocation());
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Argument 1 (input) is int but \str_pad() takes string
          Open

                          str_pad($nodes, 3, ' ', STR_PAD_LEFT).'   '.
          Severity: Minor
          Found in src/Phug/Tester/Coverage.php by phan

          Property \Phug\Tester\Coverage->renderer has undeclared type \Phug\Renderer
          Open

              protected $renderer;
          Severity: Minor
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method setOption from undeclared class \Phug\Renderer
          Open

                  $this->renderer->setOption('cache_dir', realpath($cache));
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method getOffset from undeclared class \Phug\Util\SourceLocationInterface
          Open

                      $this->coverage[$locationPath][$locationLine][$location->getOffset() - 1] = $covered;
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Call to method getOption from undeclared class \Phug\Renderer
          Open

                  $cache = realpath($this->renderer->getOption('cache_dir')).DIRECTORY_SEPARATOR;
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Checking instanceof against undeclared class \Phug\Parser\NodeInterface
          Open

                                          $node instanceof NodeInterface;
          Severity: Critical
          Found in src/Phug/Tester/Coverage.php by phan

          Argument #2 of this call to \str_pad is typically a literal or constant but isn't, but argument #1 (which is typically a variable) is a literal or constant. The arguments may be in the wrong order.
          Open

                          str_pad('Total', $pad, ' ', STR_PAD_RIGHT).
          Severity: Minor
          Found in src/Phug/Tester/Coverage.php by phan

          Avoid excessively long variable names like $coverageStoppingAllowed. Keep variable name length under 20.
          Open

              protected $coverageStoppingAllowed = true;
          Severity: Minor
          Found in src/Phug/Tester/Coverage.php by phpmd

          LongVariable

          Since: 0.2

          Detects when a field, formal or local variable is declared with a long name.

          Example

          class Something {
              protected $reallyLongIntName = -3; // VIOLATION - Field
              public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                  $otherReallyLongName = -5; // VIOLATION - Local
                  for ($interestingIntIndex = 0; // VIOLATION - For
                       $interestingIntIndex < 10;
                       $interestingIntIndex++ ) {
                  }
              }
          }

          Source https://phpmd.org/rules/naming.html#longvariable

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

                              $id = $number + 1;
          Severity: Minor
          Found in src/Phug/Tester/Coverage.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

          The variable $_nodes is not named in camelCase.
          Open

              public function dumpCoverage(bool $output = false, string $directory = null)
              {
                  if ($directory) {
                      static::addEmptyDirectory($directory);
                      foreach (static::$assets as $asset) {
          Severity: Minor
          Found in src/Phug/Tester/Coverage.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 $_coveredNodes is not named in camelCase.
          Open

              public function dumpCoverage(bool $output = false, string $directory = null)
              {
                  if ($directory) {
                      static::addEmptyDirectory($directory);
                      foreach (static::$assets as $asset) {
          Severity: Minor
          Found in src/Phug/Tester/Coverage.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 $__php is not named in camelCase.
          Open

              protected function getTemplateFile(string $file, array $vars): string
              {
                  $__php = file_get_contents(__DIR__."/../../template/$file");
                  extract($vars);
                  ob_start();
          Severity: Minor
          Found in src/Phug/Tester/Coverage.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 $_coveredNodes is not named in camelCase.
          Open

              public function dumpCoverage(bool $output = false, string $directory = null)
              {
                  if ($directory) {
                      static::addEmptyDirectory($directory);
                      foreach (static::$assets as $asset) {
          Severity: Minor
          Found in src/Phug/Tester/Coverage.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 $_coveredNodes is not named in camelCase.
          Open

              public function dumpCoverage(bool $output = false, string $directory = null)
              {
                  if ($directory) {
                      static::addEmptyDirectory($directory);
                      foreach (static::$assets as $asset) {
          Severity: Minor
          Found in src/Phug/Tester/Coverage.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 $_nodes is not named in camelCase.
          Open

              public function dumpCoverage(bool $output = false, string $directory = null)
              {
                  if ($directory) {
                      static::addEmptyDirectory($directory);
                      foreach (static::$assets as $asset) {
          Severity: Minor
          Found in src/Phug/Tester/Coverage.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 $_coveredNodes is not named in camelCase.
          Open

              public function dumpCoverage(bool $output = false, string $directory = null)
              {
                  if ($directory) {
                      static::addEmptyDirectory($directory);
                      foreach (static::$assets as $asset) {
          Severity: Minor
          Found in src/Phug/Tester/Coverage.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 $_nodes is not named in camelCase.
          Open

              public function dumpCoverage(bool $output = false, string $directory = null)
              {
                  if ($directory) {
                      static::addEmptyDirectory($directory);
                      foreach (static::$assets as $asset) {
          Severity: Minor
          Found in src/Phug/Tester/Coverage.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 $__php is not named in camelCase.
          Open

              protected function getTemplateFile(string $file, array $vars): string
              {
                  $__php = file_get_contents(__DIR__."/../../template/$file");
                  extract($vars);
                  ob_start();
          Severity: Minor
          Found in src/Phug/Tester/Coverage.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 $_nodes is not named in camelCase.
          Open

              public function dumpCoverage(bool $output = false, string $directory = null)
              {
                  if ($directory) {
                      static::addEmptyDirectory($directory);
                      foreach (static::$assets as $asset) {
          Severity: Minor
          Found in src/Phug/Tester/Coverage.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