pug-php/js-phpize

View on GitHub
src/JsPhpize/Compiler/Compiler.php

Summary

Maintainability
C
1 day
Test Coverage
A
100%

File Compiler.php has 313 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace JsPhpize\Compiler;

use JsPhpize\JsPhpize;
Severity: Minor
Found in src/JsPhpize/Compiler/Compiler.php - About 3 hrs to fix

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

    class Compiler
    {
        const DOT_DISABLED = 1;
    
        use DyiadeTrait;
    Severity: Minor
    Found in src/JsPhpize/Compiler/Compiler.php by phpmd

    Method visitDyiade has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function visitDyiade(Dyiade $dyiade, $indent)
        {
            $leftHand = $this->visitNode($dyiade->leftHand, $indent);
            $rightHand = $this->visitNode($dyiade->rightHand, $indent);
            switch ($dyiade->operator) {
    Severity: Minor
    Found in src/JsPhpize/Compiler/Compiler.php - About 1 hr to fix

      Function visitDyiade has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function visitDyiade(Dyiade $dyiade, $indent)
          {
              $leftHand = $this->visitNode($dyiade->leftHand, $indent);
              $rightHand = $this->visitNode($dyiade->rightHand, $indent);
              switch ($dyiade->operator) {
      Severity: Minor
      Found in src/JsPhpize/Compiler/Compiler.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 visitFunctionCall has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function visitFunctionCall(FunctionCall $functionCall, $indent)
          {
              $function = $functionCall->function;
              $arguments = $functionCall->arguments;
              $applicant = $functionCall->applicant;
      Severity: Minor
      Found in src/JsPhpize/Compiler/Compiler.php - About 1 hr to fix

        Method visitNodesArray has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            protected function visitNodesArray($array, $indent, $glue = '', $pattern = null, $options = 0)
        Severity: Minor
        Found in src/JsPhpize/Compiler/Compiler.php - About 35 mins to fix

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

              protected function visitFunctionCall(FunctionCall $functionCall, $indent)
              {
                  $function = $functionCall->function;
                  $arguments = $functionCall->arguments;
                  $applicant = $functionCall->applicant;
          Severity: Minor
          Found in src/JsPhpize/Compiler/Compiler.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

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

              protected function visitConstant(Constant $constant)
              {
                  $value = $constant->value;
          
                  if ($constant->type === 'string') {
          Severity: Minor
          Found in src/JsPhpize/Compiler/Compiler.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

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

              protected function visitAssignation(Assignation $assignation, $indent)
              {
                  if ($assignation->leftHand instanceof Constant && $assignation->leftHand->type === 'constant') {
                      return 'define(' .
                          var_export(strval($assignation->leftHand->value), true) . ', ' .
          Severity: Minor
          Found in src/JsPhpize/Compiler/Compiler.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

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

              protected function visitDyiade(Dyiade $dyiade, $indent)
              {
                  $leftHand = $this->visitNode($dyiade->leftHand, $indent);
                  $rightHand = $this->visitNode($dyiade->rightHand, $indent);
                  switch ($dyiade->operator) {
          Severity: Minor
          Found in src/JsPhpize/Compiler/Compiler.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 assigning values to variables in if clauses and the like (line '119', column '50').
          Open

              protected function visitBlock(Block $block, $indent)
              {
                  $head = $this->getBlockHead($block, $indent);
          
                  if (!$block->handleInstructions()) {
          Severity: Minor
          Found in src/JsPhpize/Compiler/Compiler.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

          Reference to undeclared property \JsPhpize\Nodes\Assignable->value
          Open

                          var_export(strval($assignation->leftHand->value), true) . ', ' .
          Severity: Minor
          Found in src/JsPhpize/Compiler/Compiler.php by phan

          Call to undeclared method \JsPhpize\Nodes\Assignable::popChild
          Open

                      while ($lastChild = $assignation->leftHand->popChild()) {
          Severity: Critical
          Found in src/JsPhpize/Compiler/Compiler.php by phan

          Reference to undeclared property \JsPhpize\Nodes\Assignable->type
          Open

                  if ($assignation->leftHand instanceof Constant && $assignation->leftHand->type === 'constant') {
          Severity: Minor
          Found in src/JsPhpize/Compiler/Compiler.php by phan

          Argument 1 (node) is \JsPhpize\Nodes\Assignable but \JsPhpize\Compiler\Compiler::visitNode() takes \JsPhpize\Nodes\Node defined at /code/src/JsPhpize/Compiler/Compiler.php:306
          Open

                  return $this->visitNode($assignation->leftHand, $indent) .
          Severity: Minor
          Found in src/JsPhpize/Compiler/Compiler.php by phan

          Reference to undeclared property \JsPhpize\Nodes\Assignable->children
          Open

                  if ($assignation->leftHand instanceof Variable && count($assignation->leftHand->children)) {
          Severity: Minor
          Found in src/JsPhpize/Compiler/Compiler.php by phan

          Argument 1 (node) is \JsPhpize\Nodes\Assignable but \JsPhpize\Compiler\Compiler::visitNode() takes \JsPhpize\Nodes\Node defined at /code/src/JsPhpize/Compiler/Compiler.php:306
          Open

                              $this->visitNode($assignation->leftHand, $indent),
          Severity: Minor
          Found in src/JsPhpize/Compiler/Compiler.php by phan

          Line exceeds 120 characters; contains 150 characters
          Open

                  if ($block->type === 'for' && $block->value instanceof Parenthesis && $block->value->separator === 'in' && count($block->value->nodes) >= 2) {

          Expected 0 spaces after opening bracket; newline found
          Open

                              while (

          There are no issues that match your filters.

          Category
          Status