Showing 16 of 16 total issues
Function getDynamicRoutePath
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
private function getDynamicRoutePath($routeName)
{
$argsValues = func_get_args();
array_splice($argsValues, 0, 1);
- 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 class Router has 12 public methods. Consider refactoring Router to keep number of public methods under 10. Open
class Router
{
/*** PROPERTIES ***/
- 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
Method getDynamicRoutePath
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getDynamicRoutePath($routeName)
{
$argsValues = func_get_args();
array_splice($argsValues, 0, 1);
Function findDynamicRoute
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private function findDynamicRoute($httpMethod, $requestPath)
{
$this->generateDynamicRoutes();
foreach($this->dynamicRoutes as $data){
- 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 using undefined variables such as '$this' which will lead to PHP notices. Open
"Invalid handler for '" . $this->name . "' route."
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Function getRouteByName
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function getRouteByName($routes, $routeName, $args = null)
{
foreach($routes as $routePath => $httpHandlers){
foreach($httpHandlers as $httpHandler){
if( $httpHandler['routeName'] === $routeName ){
- 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 generateDynamicRoutes
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function generateDynamicRoutes()
{
$dynamicRoutesN = count($this->dynamicRoutesData);
if( ! $dynamicRoutesN ){
Avoid variables with short names like $n. Configured minimum length is 3. Open
$n = 1;
- 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
Function generateDynamicRoutes
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function generateDynamicRoutes()
{
$dynamicRoutesN = count($this->dynamicRoutesData);
if( ! $dynamicRoutesN ){
- 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
Remove error control operator '@' on line 151. Open
private static function validateRegex($regex)
{
if( @preg_match($regex, null) === false ){
throw new Exception\InvalidRouteException("'$regex' is not a valid regex.");
}
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
run accesses the super-global variable $_SERVER. Open
public function run()
{
$httpMethod = $_SERVER['REQUEST_METHOD'];
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
shouldReturnJson accesses the super-global variable $_GET. Open
private function shouldReturnJson()
{
return (
isset($_GET['json']) ||
$this->outputFormat === 'json' ||
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
shouldReturnJson accesses the super-global variable $_SERVER. Open
private function shouldReturnJson()
{
return (
isset($_GET['json']) ||
$this->outputFormat === 'json' ||
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
The method getDynamicRoutePath() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
private function getDynamicRoutePath($routeName)
{
$argsValues = func_get_args();
array_splice($argsValues, 0, 1);
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
shouldReturnJson accesses the super-global variable $_SERVER. Open
private function shouldReturnJson()
{
return (
isset($_GET['json']) ||
$this->outputFormat === 'json' ||
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
run accesses the super-global variable $_SERVER. Open
public function run()
{
$httpMethod = $_SERVER['REQUEST_METHOD'];
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}