Avoid unused local variables such as '$iterator'. Open
if (is_null($iterator = $this->_getInnerIterator())) {
- 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
Avoid assigning values to variables in if clauses and the like (line '31', column '21'). Open
public function getInnerIterator()
{
if (is_null($iterator = $this->_getInnerIterator())) {
$this->_setInnerIterator($this->_createInnerIterator());
}
- 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
The method _createInnerIterator is not named in camelCase. Open
abstract protected function _createInnerIterator();
- 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($resultSet)
{
$this->getInnerIterator()->append($resultSet);
return true;
- 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 _getItemsForCache is not named in camelCase. Open
protected function _getItemsForCache()
{
return $this->getInnerIterator();
}
- 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 _setInnerIterator is not named in camelCase. Open
protected function _setInnerIterator(AppendIterator $iterator)
{
$this->innerIterator = $iterator;
return $this;
- 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 _getInnerIterator is not named in camelCase. Open
protected function _getInnerIterator()
{
return $this->innerIterator;
}
- 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() {
}
}