.phan/plugins/InvokePHPNativeSyntaxCheckPlugin.php

Summary

Maintainability
C
1 day
Test Coverage

File InvokePHPNativeSyntaxCheckPlugin.php has 277 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare(strict_types=1);

use ast\Node;
Severity: Minor
Found in .phan/plugins/InvokePHPNativeSyntaxCheckPlugin.php - About 2 hrs to fix

    Function streamPutContents has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        private static function streamPutContents($stream, string $file_contents): void
        {
            try {
                while (strlen($file_contents) > 0) {
                    $bytes_written = fwrite($stream, $file_contents);
    Severity: Minor
    Found in .phan/plugins/InvokePHPNativeSyntaxCheckPlugin.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 __construct has 47 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function __construct(string $binary, string $file_contents, Context $context)
        {
            $this->context = clone($context);
            $new_file_contents = Parser::removeShebang($file_contents);
            // TODO: Use symfony process
    Severity: Minor
    Found in .phan/plugins/InvokePHPNativeSyntaxCheckPlugin.php - About 1 hr to fix

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

          public function __construct(string $binary, string $file_contents, Context $context)
          {
              $this->context = clone($context);
              $new_file_contents = Parser::removeShebang($file_contents);
              // TODO: Use symfony process
      Severity: Minor
      Found in .phan/plugins/InvokePHPNativeSyntaxCheckPlugin.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 streamPutContents has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private static function streamPutContents($stream, string $file_contents): void
          {
              try {
                  while (strlen($file_contents) > 0) {
                      $bytes_written = fwrite($stream, $file_contents);
      Severity: Minor
      Found in .phan/plugins/InvokePHPNativeSyntaxCheckPlugin.php - About 1 hr to fix

        Method read has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function read(): bool
            {
                if ($this->done) {
                    return true;
                }
        Severity: Minor
        Found in .phan/plugins/InvokePHPNativeSyntaxCheckPlugin.php - About 1 hr to fix

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

              public function read(): bool
              {
                  if ($this->done) {
                      return true;
                  }
          Severity: Minor
          Found in .phan/plugins/InvokePHPNativeSyntaxCheckPlugin.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 awaitIncompleteProcesses has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              private function awaitIncompleteProcesses(CodeBase $code_base, int $max_incomplete_processes): void
              {
                  foreach ($this->processes as $i => $process) {
                      if (!$process->read()) {
                          continue;
          Severity: Minor
          Found in .phan/plugins/InvokePHPNativeSyntaxCheckPlugin.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

          Avoid using count() function in while loops.
          Open

                  while (count($this->processes) > $max_incomplete_processes) {
                      $process = array_pop($this->processes);
                      if (!$process) {
                          throw new AssertionError("Process list should be non-empty");
                      }

          CountInLoopExpression

          Since: 2.7.0

          Using count/sizeof in loops expressions is considered bad practice and is a potential source of many bugs, especially when the loop manipulates an array, as count happens on each iteration.

          Example

          class Foo {
          
            public function bar()
            {
              $array = array();
          
              for ($i = 0; count($array); $i++) {
                // ...
              }
            }
          }

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

          There are no issues that match your filters.

          Category
          Status