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
Router
has 23 functions (exceeds 20 allowed). Consider refactoring. Open
class Router implements ContainerInjectableInterface
{
use ContainerInjectableTrait;
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 addRoute
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
$method,
$mount = null,
$path = null,
$handler = null,
string $info = null
Avoid too many return
statements within this method. Open
return $this->handleInternal("500", $e->getMessage());
Avoid too many return
statements within this method. Open
return $this->handleInternal("500", $e->getMessage());
Function addRoutes
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function addRoutes(array $routes) : object
{
if (!(isset($routes["routes"]) && is_array($routes["routes"]))) {
throw new ConfigurationException("No routes found, missing key 'routes' in configuration array.");
}
- 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
Avoid unused local variables such as '$match'. Open
$match = false;
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}