GinoPane/php-nano-rest

View on GitHub

Showing 12 of 12 total issues

RequestContext has 31 functions (exceeds 20 allowed). Consider refactoring.
Open

class RequestContext
{
    /**
     * Default values for timeouts
     */
Severity: Minor
Found in src/Request/RequestContext.php - About 3 hrs to fix

    File RequestContext.php has 254 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    namespace GinoPane\NanoRest\Request;
    
    use GinoPane\NanoRest\Supplemental\HeadersProperty;
    Severity: Minor
    Found in src/Request/RequestContext.php - About 2 hrs to fix

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

          public function getRequestHeaders(): array
          {
              $headers = clone $this->headers();
      
              if (!$headers->headerExists('Content-type')) {
      Severity: Minor
      Found in src/Request/RequestContext.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 parseHeaders has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function parseHeaders(string $headers): array
          {
              $parsedHeaders = array();
      
              foreach (explode("\n", $headers) as $header) {
      Severity: Minor
      Found in src/Supplemental/Headers.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

      Rename "$charset" which has the same name as the field declared at line 80.
      Open

                      if (($charset = $this->getCharset()) && (stripos($contentType, 'charset=') === false)) {
      Severity: Major
      Found in src/Request/RequestContext.php by sonar-php

      Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

      Noncompliant Code Example

      class Foo {
        public $myField;
      
        public function doSomething() {
          $myField = 0;
          ...
        }
      }
      

      See

      Rename "$url" which has the same name as the field declared at line 115.
      Open

              $url = $this->getUrl();
      Severity: Major
      Found in src/Request/RequestContext.php by sonar-php

      Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

      Noncompliant Code Example

      class Foo {
        public $myField;
      
        public function doSomething() {
          $myField = 0;
          ...
        }
      }
      

      See

      Merge this if statement with the enclosing one.
      Open

                  if ($contentType = $this->getContentType()) {
      Severity: Major
      Found in src/Request/RequestContext.php by sonar-php

      Merging collapsible if statements increases the code's readability.

      Noncompliant Code Example

      if (condition1) {
        if (condition2) {
          ...
        }
      }
      

      Compliant Solution

      if (condition1 && condition2) {
        ...
      }
      

      Rename "$headers" which has the same name as the field declared at line 17.
      Open

              $headers = $this->headers;
      Severity: Major
      Found in src/Supplemental/Headers.php by sonar-php

      Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

      Noncompliant Code Example

      class Foo {
        public $myField;
      
        public function doSomething() {
          $myField = 0;
          ...
        }
      }
      

      See

      Class "RequestContext" has 31 methods, which is greater than 20 authorized. Split it into smaller classes.
      Open

      class RequestContext
      Severity: Major
      Found in src/Request/RequestContext.php by sonar-php

      A class that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and therefore to maintain. Above a specific threshold, it is strongly advised to refactor the class into smaller ones which focus on well defined topics.

      Rename "$contentType" which has the same name as the field declared at line 73.
      Open

                  if ($contentType = $this->getContentType()) {
      Severity: Major
      Found in src/Request/RequestContext.php by sonar-php

      Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

      Noncompliant Code Example

      class Foo {
        public $myField;
      
        public function doSomething() {
          $myField = 0;
          ...
        }
      }
      

      See

      Rename "$data" which has the same name as the field declared at line 94.
      Open

              $data = $this->getData() ? print_r($this->getData(), true) : "No data was set";
      Severity: Major
      Found in src/Request/RequestContext.php by sonar-php

      Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

      Noncompliant Code Example

      class Foo {
        public $myField;
      
        public function doSomething() {
          $myField = 0;
          ...
        }
      }
      

      See

      Rename "$requestParameters" which has the same name as the field declared at line 101.
      Open

              $requestParameters = $this->getRequestParameters()
      Severity: Major
      Found in src/Request/RequestContext.php by sonar-php

      Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

      Noncompliant Code Example

      class Foo {
        public $myField;
      
        public function doSomething() {
          $myField = 0;
          ...
        }
      }
      

      See

      Severity
      Category
      Status
      Source
      Language