Function format
has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring. Open
public static function format($key, $value, $seen = [], $collectionCount = 0, $exceptionThrown = false)
{
switch (true) {
case $value instanceof Model:
$namespace = explode('\\', get_class($value));
- 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 format
has 113 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function format($key, $value, $seen = [], $collectionCount = 0, $exceptionThrown = false)
{
switch (true) {
case $value instanceof Model:
$namespace = explode('\\', get_class($value));
Function dumpModel
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
public static function dumpModel(Model $model)
{
$data_access = function ($var) {
return $this->$var;
};
- 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 dumpModel
has 84 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function dumpModel(Model $model)
{
$data_access = function ($var) {
return $this->$var;
};
Method format
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function format($key, $value, $seen = [], $collectionCount = 0, $exceptionThrown = false)
The method dumpModel() has 104 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public static function dumpModel(Model $model)
{
$data_access = function ($var) {
return $this->$var;
};
- Exclude checks
The method format() has 134 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public static function format($key, $value, $seen = [], $collectionCount = 0, $exceptionThrown = false)
{
switch (true) {
case $value instanceof Model:
$namespace = explode('\\', get_class($value));
- Exclude checks
The method format() has an NPath complexity of 208. The configured NPath complexity threshold is 200. Open
public static function format($key, $value, $seen = [], $collectionCount = 0, $exceptionThrown = false)
{
switch (true) {
case $value instanceof Model:
$namespace = explode('\\', get_class($value));
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method dumpModel() has an NPath complexity of 1728. The configured NPath complexity threshold is 200. Open
public static function dumpModel(Model $model)
{
$data_access = function ($var) {
return $this->$var;
};
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method format() has a Cyclomatic Complexity of 23. The configured cyclomatic complexity threshold is 10. Open
public static function format($key, $value, $seen = [], $collectionCount = 0, $exceptionThrown = false)
{
switch (true) {
case $value instanceof Model:
$namespace = explode('\\', get_class($value));
- 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
The method dumpModel() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10. Open
public static function dumpModel(Model $model)
{
$data_access = function ($var) {
return $this->$var;
};
- 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
Avoid using undefined variables such as '$this' which will lead to PHP notices. Open
$value = $this->_data->$key;
- 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
Avoid using undefined variables such as '$this' which will lead to PHP notices. Open
$output .= " <span><strong>connection</strong></span> => ".$this->connection->name."\n";
- 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
Avoid using undefined variables such as '$this' which will lead to PHP notices. Open
foreach (get_class_methods($this) as $method) {
- 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
Avoid using undefined variables such as '$this' which will lead to PHP notices. Open
$value = $this->{$key};
- 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
Avoid using undefined variables such as '$this' which will lead to PHP notices. Open
$output .= " <span><strong>table</strong></span> => ".$this->table."\n";
- 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
Avoid using undefined variables such as '$objstrings' which will lead to PHP notices. Open
$objstrings[] = \Automatorm\Orm\Dump::safeTruncate($obj);
- 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
Avoid using undefined variables such as '$this' which will lead to PHP notices. Open
$output .= " <span><strong>id</strong></span> => ".$this->id."\n";
- 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
Avoid using undefined variables such as '$this' which will lead to PHP notices. Open
return $this->$var;
- 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
Avoid using undefined variables such as '$this' which will lead to PHP notices. Open
$value = $this->_data->join($key, ['id' => array_slice($ids, 0, \Automatorm\Orm\Dump::$id_limit)]);
- 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
Avoid using undefined variables such as '$this' which will lead to PHP notices. Open
$data = $data_access->bindTo($this->_data, $this->_data);
- 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
Avoid using undefined variables such as '$this' which will lead to PHP notices. Open
[$contents['column_name'] => $this->id],
- 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
Avoid using undefined variables such as '$objstrings' which will lead to PHP notices. Open
$display4 = implode(',', $objstrings);
- 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
Avoid using undefined variables such as '$this' which will lead to PHP notices. Open
$data = $data_access->bindTo($this->_data, $this->_data);
- 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
Avoid using undefined variables such as '$this' which will lead to PHP notices. Open
$ids = $this->{$key}->id->toArray();
- 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
Avoid using undefined variables such as '$this' which will lead to PHP notices. Open
foreach (get_object_vars($this) as $key => $value) {
- 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
Avoid using undefined variables such as '$this' which will lead to PHP notices. Open
$value = $this->$method();
- 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
Avoid using undefined variables such as '$this' which will lead to PHP notices. Open
$value = $this->_data->$key;
- 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
Avoid using undefined variables such as '$this' which will lead to PHP notices. Open
$count = $this->_data->joinCount($key, []);
- 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
Variable $this
is undeclared Open
return $this->$var;
- Exclude checks
Variable $this
is undeclared Open
$data = $data_access->bindTo($this->_data, $this->_data);
- Exclude checks
Variable $this
is undeclared Open
foreach (get_object_vars($this) as $key => $value) {
- Exclude checks
Argument 1 (str)
is \Automatorm\Orm\Model|\JsonSerializable
but \substr()
takes string
Open
return htmlspecialchars(substr($string, 0, $length)) . '...';
- Exclude checks
Argument 1 (str)
is \ArrayAccess|\Automatorm\Orm\Collection|\Automatorm\Orm\Model|\Countable|\Iterator|\JsonSerializable|\Traversable|iterable
but \substr()
takes string
Open
return htmlspecialchars(substr($string, 0, $length)) . '...';
- Exclude checks
Argument 1 (string)
is ?\Automatorm\Orm\Model|\Automatorm\Orm\Model|\JsonSerializable
but \htmlspecialchars()
takes string
Open
return htmlspecialchars($string);
- Exclude checks
Variable $this
is undeclared Open
$output .= " <span><strong>table</strong></span> => ".$this->table."\n";
- Exclude checks
Suspicious type \Automatorm\Orm\Collection
of a variable or expression used to build a string. (Expected type to be able to cast to a string) Open
$display3 = '"' . $value .'"';
- Exclude checks
Suspicious type null
of a variable or expression used to build a string. (Expected type to be able to cast to a string) Open
$display3 = '"' . $value .'"';
- Exclude checks
Variable $this
is undeclared Open
$value = $this->_data->$key;
- Exclude checks
Checking instanceof against undeclared class \Automatorm\Orm\DateTimeInterface
(Did you mean interface \DateTimeInterface) Open
case $value instanceof DateTimeInterface:
- Exclude checks
Variable $this
is undeclared Open
$output .= " <span><strong>connection</strong></span> => ".$this->connection->name."\n";
- Exclude checks
Argument 1 (string)
is \Automatorm\Orm\Model|\JsonSerializable
but \htmlspecialchars()
takes string
Open
return htmlspecialchars($string);
- Exclude checks
Argument 1 (string)
is ?\Automatorm\Orm\Model|\Automatorm\Orm\Model|\JsonSerializable
but \strlen()
takes string
Open
if (strlen($string) > $length) {
- Exclude checks
Argument 1 (string)
is \ArrayAccess|\Automatorm\Orm\Collection|\Automatorm\Orm\Model|\Countable|\Iterator|\JsonSerializable|\Traversable|iterable
but \strlen()
takes string
Open
if (strlen($string) > $length) {
- Exclude checks
Variable $this
is undeclared Open
$value = $this->_data->$key;
- Exclude checks
Argument 1 (str)
is ?\Automatorm\Orm\Model|\Automatorm\Orm\Model|\JsonSerializable
but \substr()
takes string
Open
return htmlspecialchars(substr($string, 0, $length)) . '...';
- Exclude checks
Expected an object instance or a class name when accessing a static property, but saw an expression with type null
Open
$table = $value::$tablename;
- Exclude checks
Variable $this
is undeclared Open
[$contents['column_name'] => $this->id],
- Exclude checks
Variable $this
is undeclared Open
$value = $this->{$key};
- Exclude checks
Argument 1 (object)
is null
but \get_class()
takes object
Open
$namespace = explode('\\', get_class($value));
- Exclude checks
Variable $this
is undeclared Open
$count = $this->_data->joinCount($key, []);
- Exclude checks
Variable $this
is undeclared Open
$value = $this->_data->join($key, ['id' => array_slice($ids, 0, \Automatorm\Orm\Dump::$id_limit)]);
- Exclude checks
Argument 1 (string)
is \Automatorm\Orm\Model|\JsonSerializable
but \strlen()
takes string
Open
if (strlen($string) > $length) {
- Exclude checks
Static property 'tablename'
on \Automatorm\Orm\Collection
is undeclared Open
$table = $value::$tablename;
- Exclude checks
Argument 1 (object)
is null
but \method_exists()
takes object|string
Open
if (method_exists($value, '__toString')) {
- Exclude checks
Variable $this
is undeclared Open
$ids = $this->{$key}->id->toArray();
- Exclude checks
null
passed to foreach instead of array Open
foreach ($value as $obj) {
- Exclude checks
null
passed to foreach instead of array Open
foreach ($value as $obj) {
- Exclude checks
Variable $this
is undeclared Open
$output .= " <span><strong>id</strong></span> => ".$this->id."\n";
- Exclude checks
Variable $objstrings
was undeclared, but array fields are being added to it. Open
$objstrings[] = \Automatorm\Orm\Dump::safeTruncate($obj);
- Exclude checks
Variable $this
is undeclared Open
$value = $this->$method();
- Exclude checks
Argument 1 (object)
is null
but \get_class()
takes object
Open
$namespace = explode('\\', get_class($value));
- Exclude checks
Call to method format
on non-class type null
Open
$display3 = $value->format('Y-m-d H:i:s');
- Exclude checks
Argument 1 (string)
is \ArrayAccess|\Automatorm\Orm\Collection|\Automatorm\Orm\Model|\Countable|\Iterator|\JsonSerializable|\Traversable|iterable
but \htmlspecialchars()
takes string
Open
return htmlspecialchars($string);
- Exclude checks
Variable $this
is undeclared Open
foreach (get_class_methods($this) as $method) {
- Exclude checks
Argument 1 (object)
is null
but \get_class()
takes object
Open
if (get_class($value) == 'Automatorm\\Orm\\Model') {
- Exclude checks
The property $id_limit is not named in camelCase. Open
class Dump
{
public static $url_prefix = null;
public static $id_limit = 30;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $url_prefix is not named in camelCase. Open
class Dump
{
public static $url_prefix = null;
public static $id_limit = 30;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The variable $data_access is not named in camelCase. Open
public static function dumpModel(Model $model)
{
$data_access = function ($var) {
return $this->$var;
};
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $data_access is not named in camelCase. Open
public static function dumpModel(Model $model)
{
$data_access = function ($var) {
return $this->$var;
};
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}