Method parse
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function parse(Request $request)
{
$content = $request->getContent();
if (!empty($content) && self::HTTP_DELETE == $request->getMethod()) {
Method __construct
has 10 arguments (exceeds 4 allowed). Consider refactoring. Open
ResourceEntityMapper $resourceEntityMapper,
DocNavigator $docNavigator,
FilterParser $filterParser,
PaginationParser $paginationParser,
BodyParser $bodyParser,
Function parse
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function parse(Request $request)
{
$content = $request->getContent();
if (!empty($content) && self::HTTP_DELETE == $request->getMethod()) {
- 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
The method __construct has 10 parameters. Consider reducing the number of parameters to less than 10. Open
public function __construct(
ResourceEntityMapper $resourceEntityMapper,
DocNavigator $docNavigator,
FilterParser $filterParser,
PaginationParser $paginationParser,
- Exclude checks
The class Parser has a coupling between objects value of 30. Consider to reduce the number of dependencies under 13. Open
class Parser
{
const HTTP_OPTIONS = 'OPTIONS',
HTTP_HEAD = 'HEAD',
HTTP_GET = 'GET',
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
Missing class import via use statement (line '330', column '23'). Open
throw new \Exception(self::ERROR_NO_API_BASE_PATH);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
The method parseSparseFields uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$fields = [$primaryType => $callback($fields)];
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method parseSorting uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$order = Params::DESCENDING_ORDER;
$field = substr($field, 1);
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid unused private fields such as '$magicServices'. Open
private $magicServices;
- Read upRead up
- Exclude checks
UnusedPrivateField
Since: 0.2
Detects when a private field is declared and/or assigned a value, but not used.
Example
class Something
{
private static $FOO = 2; // Unused
private $i = 5; // Unused
private $j = 6;
public function addOne()
{
return $this->j++;
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield
Avoid variables with short names like $mm. Configured minimum length is 3. Open
MetadataMinerInterface $mm,
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $mm. Configured minimum length is 3. Open
private $mm;
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Expected 1 space after FUNCTION keyword; 0 found Open
array_walk($include, function(&$relationship) {
- Exclude checks
Multi-line function declarations must define one parameter per line Open
Request $request, $part = self::PRIMARY_RESOURCE_TYPE
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "null" but found "NULL" Open
return isset($path[$part]) ? $path[$part] : NULL;
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
$callback = function($sort, $type) use (&$sorting) {
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
$callback = function($fields) {
- Exclude checks
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line Open
{
- Exclude checks
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line Open
{
- Exclude checks
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line Open
{
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
$request, self::PRIMARY_RESOURCE_RELATIONSHIP
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
self::ERROR_ACTION_NOT_ALLOWED, implode(', ', $allowedMethods)
- Exclude checks
Inline control structures are not allowed Open
if (isset($map[$type])) return $map[$type];
- Exclude checks
Line exceeds 120 characters; contains 183 characters Open
ERROR_RELATIONSHIP_UNDEFINED = "The requested relationship is undefined or can only be accessed through its own URL, filtering by its relationship with the current resource.",
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
ERROR_MULTIPLE_IDS_WITH_RELATIONSHIP = "Multiple Ids are not supported when requesting a resource field or link.",
- Exclude checks
Line exceeds 120 characters; contains 133 characters Open
ERROR_ACTION_NOT_ALLOWED = "The attempted action is not allowed on the requested resource. Supported HTTP methods are [%s].",
- Exclude checks
Expected 0 spaces after opening bracket; newline found Open
if (
- Exclude checks