Function filter
has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring. Open
public function filter($filter, $invertAffix = false)
{
$copy = $this->container;
if (is_array($filter)) {
- 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
Collection
has 32 functions (exceeds 20 allowed). Consider refactoring. Open
class Collection implements \ArrayAccess, \Iterator, \Countable, \JsonSerializable
{
// From Hodgepodge
protected $container = [];
File Collection.php
has 298 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace Automatorm\Orm;
use Automatorm\Exception;
use Automatorm\OperatorParser;
Method filter
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function filter($filter, $invertAffix = false)
{
$copy = $this->container;
if (is_array($filter)) {
Function __call
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function __call($name, $args)
{
// If we use Model::COUNT_ONLY on empty container, return 0
if (count($this->container) == 0 && is_numeric($args[1]) && ($args[1] & Model::COUNT_ONLY)) {
return 0;
- 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 unique
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function unique()
{
$copy = $this->container;
$clobberlist = [];
$modelclobberlist = [];
- 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 __call
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function __call($name, $args)
{
// If we use Model::COUNT_ONLY on empty container, return 0
if (count($this->container) == 0 && is_numeric($args[1]) && ($args[1] & Model::COUNT_ONLY)) {
return 0;
Avoid too many return
statements within this method. Open
return new static($list);
Function __get
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function __get($parameter)
{
$list = array();
if ($this->container[0] instanceof Model and $this->container[0]->_data->externalKeyExists($parameter)) {
- 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 __call() has an NPath complexity of 216. The configured NPath complexity threshold is 200. Open
public function __call($name, $args)
{
// If we use Model::COUNT_ONLY on empty container, return 0
if (count($this->container) == 0 && is_numeric($args[1]) && ($args[1] & Model::COUNT_ONLY)) {
return 0;
- 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 __call() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. Open
public function __call($name, $args)
{
// If we use Model::COUNT_ONLY on empty container, return 0
if (count($this->container) == 0 && is_numeric($args[1]) && ($args[1] & Model::COUNT_ONLY)) {
return 0;
- 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 filter() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. Open
public function filter($filter, $invertAffix = false)
{
$copy = $this->container;
if (is_array($filter)) {
- 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
Missing class import via use statement (line '433', column '23'). Open
throw new \InvalidArgumentException('Orm\Collection->filter() expects an array or callable');
- 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
Missing class import via use statement (line '336', column '27'). Open
throw new \InvalidArgumentException("Orm\Collection->add() expects argument {$count} to be an array");
- 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
Missing class import via use statement (line '184', column '23'). Open
throw new \InvalidArgumentException('Orm\Collection::__construct() expects an array - ' . gettype($array) . ' given');
- 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
Saw a dynamic usage of an instance property with a name of type callable
but expected the name to be a string Open
return strnatcasecmp($a->{$key}, $b->{$key});
- Exclude checks
Saw an @param annotation for function,
but it was not found in the param list of function sortById(array $listOfIds) : \Automatorm\Orm\Collection
Open
* @param callable $function Callable to use to sort the array
- Exclude checks
Each PHP statement must be on a line by itself Open
return Data::groupJoin($this->map(function ($a) { return $a->getModel(); }), $parameter);
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
* Return a plain PHP array version of the internal container using the supplied key/value values of the model object
- Exclude checks
Line exceeds 120 characters; contains 125 characters Open
* @param $value For Collections of Models, return the specified property name instead of the Model object as the "Value"
- Exclude checks
Line exceeds 120 characters; contains 174 characters Open
if ($this->container[0] instanceof WrappedModel and !property_exists($this->container[0], $parameter) and $this->container[0]->_data->externalKeyExists($parameter)) {
- Exclude checks
Line exceeds 120 characters; contains 125 characters Open
throw new Exception\Collection('Cannot directly set properties on a collection', ['name' => $name, 'value' => $arg]);
- Exclude checks
Line exceeds 120 characters; contains 130 characters Open
throw new \InvalidArgumentException('Orm\Collection::__construct() expects an array - ' . gettype($array) . ' given');
- Exclude checks
Inline control structures are not allowed Open
if (!$this->container) return new static();
- Exclude checks
Opening brace must be the last content on the line Open
return Data::groupJoin($this->map(function ($a) { return $a->getModel(); }), $parameter);
- Exclude checks
Closing brace must be on a line by itself Open
return Data::groupJoin($this->map(function ($a) { return $a->getModel(); }), $parameter);
- Exclude checks