src/Phan/Bootstrap.php

Summary

Maintainability
D
2 days
Test Coverage

File Bootstrap.php has 317 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare(strict_types=1);

/**
Severity: Minor
Found in src/Phan/Bootstrap.php - About 3 hrs to fix

    Function phan_error_handler has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

    function phan_error_handler(int $errno, string $errstr, string $errfile, int $errline): bool
    {
        global $__no_echo_phan_errors;
        if ($__no_echo_phan_errors) {
            if ($__no_echo_phan_errors instanceof Closure) {
    Severity: Minor
    Found in src/Phan/Bootstrap.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

    Function phan_print_backtrace has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    function phan_print_backtrace(bool $is_crash = false, int $frames_to_skip = 2): void
    {
        // Uncomment this if even trying to print the details would crash
        /*
        ob_start();
    Severity: Minor
    Found in src/Phan/Bootstrap.php - About 2 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 phan_error_handler has 52 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function phan_error_handler(int $errno, string $errstr, string $errfile, int $errline): bool
    {
        global $__no_echo_phan_errors;
        if ($__no_echo_phan_errors) {
            if ($__no_echo_phan_errors instanceof Closure) {
    Severity: Major
    Found in src/Phan/Bootstrap.php - About 2 hrs to fix

      Method phan_output_ast_installation_instructions has 44 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function phan_output_ast_installation_instructions(): void
      {
          require_once __DIR__ . '/Library/StringUtil.php';
          $ini_path = php_ini_loaded_file() ?: '(php.ini path could not be determined - try creating one at ' . dirname(PHP_BINARY) . '\\php.ini as a new empty file, or one based on php.ini.development or php.ini.production)';
          $configured_extension_dir = ini_get('extension_dir');
      Severity: Minor
      Found in src/Phan/Bootstrap.php - About 1 hr to fix

        Method phan_print_backtrace has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function phan_print_backtrace(bool $is_crash = false, int $frames_to_skip = 2): void
        {
            // Uncomment this if even trying to print the details would crash
            /*
            ob_start();
        Severity: Minor
        Found in src/Phan/Bootstrap.php - About 1 hr to fix

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

          function phan_output_ast_installation_instructions(): void
          {
              require_once __DIR__ . '/Library/StringUtil.php';
              $ini_path = php_ini_loaded_file() ?: '(php.ini path could not be determined - try creating one at ' . dirname(PHP_BINARY) . '\\php.ini as a new empty file, or one based on php.ini.development or php.ini.production)';
              $configured_extension_dir = ini_get('extension_dir');
          Severity: Minor
          Found in src/Phan/Bootstrap.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

          Avoid too many return statements within this method.
          Open

                  return true;
          Severity: Major
          Found in src/Phan/Bootstrap.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return true;
            Severity: Major
            Found in src/Phan/Bootstrap.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return false;
              Severity: Major
              Found in src/Phan/Bootstrap.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return true;
                Severity: Major
                Found in src/Phan/Bootstrap.php - About 30 mins to fix

                  The function phan_error_handler() has an NPath complexity of 9720. The configured NPath complexity threshold is 200.
                  Open

                  function phan_error_handler(int $errno, string $errstr, string $errfile, int $errline): bool
                  {
                      global $__no_echo_phan_errors;
                      if ($__no_echo_phan_errors) {
                          if ($__no_echo_phan_errors instanceof Closure) {
                  Severity: Minor
                  Found in src/Phan/Bootstrap.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 function phan_output_ast_installation_instructions() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
                  Open

                  function phan_output_ast_installation_instructions(): void
                  {
                      require_once __DIR__ . '/Library/StringUtil.php';
                      $ini_path = php_ini_loaded_file() ?: '(php.ini path could not be determined - try creating one at ' . dirname(PHP_BINARY) . '\\php.ini as a new empty file, or one based on php.ini.development or php.ini.production)';
                      $configured_extension_dir = ini_get('extension_dir');
                  Severity: Minor
                  Found in src/Phan/Bootstrap.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

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

                  function phan_error_handler(int $errno, string $errstr, string $errfile, int $errline): bool
                  {
                      global $__no_echo_phan_errors;
                      if ($__no_echo_phan_errors) {
                          if ($__no_echo_phan_errors instanceof Closure) {
                  Severity: Minor
                  Found in src/Phan/Bootstrap.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

                  The function phan_error_handler() contains an exit expression.
                  Open

                      exit(EXIT_FAILURE);
                  Severity: Minor
                  Found in src/Phan/Bootstrap.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

                  There are no issues that match your filters.

                  Category
                  Status