Showing 12 of 12 total issues
RequestContext
has 31 functions (exceeds 20 allowed). Consider refactoring. Open
class RequestContext
{
/**
* Default values for timeouts
*/
File RequestContext.php
has 254 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace GinoPane\NanoRest\Request;
use GinoPane\NanoRest\Supplemental\HeadersProperty;
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')) {
- Read upRead up
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) {
- Read upRead up
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 "$headers" which has the same name as the field declared at line 17. Open
$headers = $this->headers;
- Read upRead up
- Exclude checks
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
- CERT, DCL51-J. - Do not shadow or obscure identifiers in subscopes
Rename "$contentType" which has the same name as the field declared at line 73. Open
if ($contentType = $this->getContentType()) {
- Read upRead up
- Exclude checks
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
- CERT, DCL51-J. - Do not shadow or obscure identifiers in subscopes
Class "RequestContext" has 31 methods, which is greater than 20 authorized. Split it into smaller classes. Open
class RequestContext
- Read upRead up
- Exclude checks
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 "$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";
- Read upRead up
- Exclude checks
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
- CERT, DCL51-J. - Do not shadow or obscure identifiers in subscopes
Rename "$charset" which has the same name as the field declared at line 80. Open
if (($charset = $this->getCharset()) && (stripos($contentType, 'charset=') === false)) {
- Read upRead up
- Exclude checks
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
- CERT, DCL51-J. - Do not shadow or obscure identifiers in subscopes
Rename "$url" which has the same name as the field declared at line 115. Open
$url = $this->getUrl();
- Read upRead up
- Exclude checks
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
- CERT, DCL51-J. - Do not shadow or obscure identifiers in subscopes
Merge this if statement with the enclosing one. Open
if ($contentType = $this->getContentType()) {
- Read upRead up
- Exclude checks
Merging collapsible if
statements increases the code's readability.
Noncompliant Code Example
if (condition1) { if (condition2) { ... } }
Compliant Solution
if (condition1 && condition2) { ... }
Rename "$requestParameters" which has the same name as the field declared at line 101. Open
$requestParameters = $this->getRequestParameters()
- Read upRead up
- Exclude checks
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
- CERT, DCL51-J. - Do not shadow or obscure identifiers in subscopes