Showing 66 of 66 total issues
The class Router has 15 public methods. Consider refactoring Router to keep number of public methods under 10. Open
class Router implements ContainerInjectableInterface
{
use ContainerInjectableTrait;
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
The class RouteHandler has an overall complexity of 80 which is very high. The configured complexity threshold is 50. Open
class RouteHandler
{
/**
* @var ContainerInterface $di the dependency/service container.
*/
- Exclude checks
Router
has 23 functions (exceeds 20 allowed). Consider refactoring. Open
class Router implements ContainerInjectableInterface
{
use ContainerInjectableTrait;
File RouteHandler.php
has 270 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace Anax\Route;
use Anax\Commons\ContainerInjectableInterface;
Method handleAsControllerAction
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function handleAsControllerAction(array $callable)
{
$class = $callable[0];
$action = $callable[1];
$args = $callable[2];
Function handleAsControllerAction
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
protected function handleAsControllerAction(array $callable)
{
$class = $callable[0];
$action = $callable[1];
$args = $callable[2];
- 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 handleAsInvocableClass
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
protected function handleAsInvocableClass(string $class)
{
$obj = new $class();
// $class = $callable[0];
$action = "__invoke";
- 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
Method handleAsInvocableClass
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function handleAsInvocableClass(string $class)
{
$obj = new $class();
// $class = $callable[0];
$action = "__invoke";
Avoid excessively long variable names like $matchedQueryToMountPath. Keep variable name length under 20. Open
$matchedQueryToMountPath = strncmp($query, $mount, $charsToMatch) === 0 ? true : false;
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Method match
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function match(
?string $mount,
?string $relativePath,
?string $absolutePath,
?string $query,
Function match
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function match(
?string $mount,
?string $relativePath,
?string $absolutePath,
?string $query,
- 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 handle
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function handle(
?string $method,
?string $path,
$action,
array $arguments = [],
- 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 handle
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function handle($path, $method = null)
{
try {
$match = false;
foreach ($this->routes as $route) {
- 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
Method handle
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function handle(
?string $method,
?string $path,
$action,
array $arguments = [],
Method isControllerAction
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function isControllerAction(
?string $method,
?string $path,
string $class
) {
Function isControllerAction
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
protected function isControllerAction(
?string $method,
?string $path,
string $class
) {
- 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
Consider simplifying this complex logical expression. Open
if ($di
&& is_array($action)
&& isset($action[0])
&& isset($action[1])
&& is_string($action[0])
Avoid variables with short names like $di. Configured minimum length is 3. Open
public function getHandlerType(ContainerInterface $di = null) : string
- 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 $di. Configured minimum length is 3. Open
protected $di;
- 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 $di. Configured minimum length is 3. Open
ContainerInterface $di = null
- 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;
}
}
}