The class AbstractCollection has an overall complexity of 57 which is very high. The configured complexity threshold is 50. Open
abstract class AbstractCollection extends AbstractHasher implements CollectionInterface
{
protected $items;
/**
- Exclude checks
AbstractCollection
has 23 functions (exceeds 20 allowed). Consider refactoring. Open
abstract class AbstractCollection extends AbstractHasher implements CollectionInterface
{
protected $items;
/**
Function _arraySearch
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
protected function _arraySearch(&$array, $value, $strict = false)
{
// Regular array matching
if (is_array($array)) {
return array_search($value, $array, $strict);
- 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 _arrayUnset
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function _arrayUnset(&$array, $key)
{
if (is_array($array)) {
if (isset($array[$key])) {
unset($array[$key]);
- 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 too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return $array->removeItemByKey($key);
The method _findItem has a boolean flag argument $strict, which is a certain sign of a Single Responsibility Principle violation. Open
public function _findItem($item, $strict = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method _arraySearch has a boolean flag argument $strict, which is a certain sign of a Single Responsibility Principle violation. Open
protected function _arraySearch(&$array, $value, $strict = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Avoid assigning values to variables in if clauses and the like (line '134', column '14'). Open
protected function _removeItem($item)
{
if (($key = $this->_findItem($item, true)) !== false) {
return $this->_arrayUnset($this->items, $key);
}
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid unused parameters such as '$item'. Open
protected function _getItemUniqueKey($item)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused local variables such as '$_key'. Open
foreach ($items as $_key => $_item) {
- 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
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
The variable $_value is not named in camelCase. Open
protected function _arraySearch(&$array, $value, $strict = false)
{
// Regular array matching
if (is_array($array)) {
return array_search($value, $array, $strict);
- 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 $_idx is not named in camelCase. Open
protected function _arraySearch(&$array, $value, $strict = false)
{
// Regular array matching
if (is_array($array)) {
return array_search($value, $array, $strict);
- 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 $_value is not named in camelCase. Open
protected function _arraySearch(&$array, $value, $strict = false)
{
// Regular array matching
if (is_array($array)) {
return array_search($value, $array, $strict);
- 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 $_item is not named in camelCase. Open
protected function _addItems($items)
{
foreach ($items as $_key => $_item) {
$this->_validateItem($_item);
$this->_addItem($_item);
- 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 $_idx is not named in camelCase. Open
protected function _arraySearch(&$array, $value, $strict = false)
{
// Regular array matching
if (is_array($array)) {
return array_search($value, $array, $strict);
- 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 $_value is not named in camelCase. Open
protected function _arraySearch(&$array, $value, $strict = false)
{
// Regular array matching
if (is_array($array)) {
return array_search($value, $array, $strict);
- 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 $_item is not named in camelCase. Open
protected function _addItems($items)
{
foreach ($items as $_key => $_item) {
$this->_validateItem($_item);
$this->_addItem($_item);
- 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 $_key is not named in camelCase. Open
protected function _addItems($items)
{
foreach ($items as $_key => $_item) {
$this->_validateItem($_item);
$this->_addItem($_item);
- 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 $_idx is not named in camelCase. Open
protected function _arraySearch(&$array, $value, $strict = false)
{
// Regular array matching
if (is_array($array)) {
return array_search($value, $array, $strict);
- 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 $_item is not named in camelCase. Open
protected function _addItems($items)
{
foreach ($items as $_key => $_item) {
$this->_validateItem($_item);
$this->_addItem($_item);
- 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 method _addItems is not named in camelCase. Open
protected function _addItems($items)
{
foreach ($items as $_key => $_item) {
$this->_validateItem($_item);
$this->_addItem($_item);
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _setItem is not named in camelCase. Open
protected function _setItem($key, $item)
{
return $this->_arraySet($this->items, $item, $key);
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _hasItemKey is not named in camelCase. Open
protected function _hasItemKey($key)
{
return $this->_arrayKeyExists($this->items, $key);
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _arrayGet is not named in camelCase. Open
protected function _arrayGet(&$list, $key, $default = null)
{
if (is_array($list)) {
return isset($list[$key])
? $list[$key]
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _arrayConvert is not named in camelCase. Open
protected function _arrayConvert(&$list)
{
if (is_array($list)) {
return $list;
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _addItem is not named in camelCase. Open
protected function _addItem($item)
{
$key = $this->_getItemUniqueKey($item);
return $this->_arraySet($this->items, $item, $key);
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _hasItem is not named in camelCase. Open
protected function _hasItem($item)
{
return $this->_findItem($item, true) !== false;
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _getItemKey is not named in camelCase. Open
protected function _getItemKey($item)
{
return $this->_hash($item);
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _isValidItem is not named in camelCase. Open
protected function _isValidItem($item)
{
try {
$this->_validateItem($item);
} catch (Exception $ex) {
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _findItem is not named in camelCase. Open
public function _findItem($item, $strict = false)
{
return $this->_arraySearch($this->items, $item, $strict);
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _arraySearch is not named in camelCase. Open
protected function _arraySearch(&$array, $value, $strict = false)
{
// Regular array matching
if (is_array($array)) {
return array_search($value, $array, $strict);
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _validateItemList is not named in camelCase. Open
protected function _validateItemList($items)
{
if (!is_array($items) && !($items instanceof \Traversable)) {
throw new UnexpectedValueException(sprintf('Must be a valid item list'));
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _getItem is not named in camelCase. Open
protected function _getItem($key, $default = null)
{
return $this->_arrayGet($this->items, $key, $default);
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _getItemUniqueKey is not named in camelCase. Open
protected function _getItemUniqueKey($item)
{
return count($this->items);
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _arrayKeyExists is not named in camelCase. Open
protected function _arrayKeyExists(&$list, $key)
{
if (is_array($list)) {
return array_key_exists($key, $list);
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _setItems is not named in camelCase. Open
protected function _setItems($items)
{
$this->_validateItemList($items);
$this->items = $items;
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _removeItem is not named in camelCase. Open
protected function _removeItem($item)
{
if (($key = $this->_findItem($item, true)) !== false) {
return $this->_arrayUnset($this->items, $key);
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _arraySet is not named in camelCase. Open
protected function _arraySet(&$list, $item, $key)
{
if (is_array($list)) {
$list[$key] = $item;
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _validateItem is not named in camelCase. Open
abstract protected function _validateItem($item);
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _construct is not named in camelCase. Open
protected function _construct()
{
$this->items = array();
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _getItems is not named in camelCase. Open
protected function _getItems()
{
return $this->items;
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _arrayUnset is not named in camelCase. Open
protected function _arrayUnset(&$array, $key)
{
if (is_array($array)) {
if (isset($array[$key])) {
unset($array[$key]);
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}