shawnrice/alphred

View on GitHub
classes/Request.php

Summary

Maintainability
D
1 day
Test Coverage

Function execute has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    public function execute( $code = false ) {

        // Set a preliminary HTTP response code of 0 (not defined)
        $this->code = 0;

Severity: Minor
Found in classes/Request.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

Request has 24 functions (exceeds 20 allowed). Consider refactoring.
Open

class Request {

    /**
     * The internal cURL handler
     * @var Resource
Severity: Minor
Found in classes/Request.php - About 2 hrs to fix

    Method execute has 48 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function execute( $code = false ) {
    
            // Set a preliminary HTTP response code of 0 (not defined)
            $this->code = 0;
    
    
    Severity: Minor
    Found in classes/Request.php - About 1 hr to fix

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

          public function add_header( $header ) {
              // Check the variable. We expect string, but let's be sure.
              if ( is_string( $header ) ) {
                  // Since it's a string, just push it into the headers array.
                  array_push( $this->headers, $header );
      Severity: Minor
      Found in classes/Request.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 set_caches has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          private function set_caches( $options ) {
              if ( ! isset( $options['cache_bin' ] ) ) {
                  // exit early if no cache bin is set
                  return;
              }
      Severity: Minor
      Found in classes/Request.php - About 45 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 too many return statements within this method.
      Open

              return file_get_contents( $this->get_cache_file() );
      Severity: Major
      Found in classes/Request.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                        return [ 'code' => 0, 'data' => false ];
        Severity: Major
        Found in classes/Request.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                      return $this->results;
          Severity: Major
          Found in classes/Request.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                            return false;
            Severity: Major
            Found in classes/Request.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return [ 'code' => $this->code, 'data' => $this->results ];
              Severity: Major
              Found in classes/Request.php - About 30 mins to fix

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

                    private function clear_directory( $dir ) {
                        if ( ! file_exists( $dir ) || ! is_dir( $dir ) || '.' === $dir ) {
                            // Throw an exception because this is a bad request to clear the cache
                            throw new Exception( "Cannot clear directory: `{$dir}`", 3 );
                        }
                Severity: Minor
                Found in classes/Request.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

                There are no issues that match your filters.

                Category
                Status