for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Thruster\Component\XMLIterator;
use Iterator;
use BadMethodCallException;
/**
* Class Iteration
*
* @package Thruster\Component\XMLIterator
* @author Aurimas Niekis <[email protected]>
*/
class Iteration implements Iterator
{
* @var XMLReader
private $reader;
* @var bool
private $valid;
* @var int
private $index;
private $skipNextRead;
public function __construct(XMLReader $reader)
$this->reader = $reader;
}
* skip the next read on next next()
* this is useful of the reader has moved to the next node already inside a foreach iteration and the next
* next would move the reader one off.
* @see next
public function skipNextRead()
$this->skipNextRead = true;
* @return XMLReader
public function current()
return $this->reader;
public function next()
$this->index++;
if ($this->skipNextRead) {
$this->skipNextRead = false;
$this->valid = $this->reader->nodeType;
$valid
boolean
$this->reader->nodeType
integer
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.
$answer = 42; $correct = false; $correct = (bool) $answer;
} else {
$this->valid = $this->reader->read();
public function key()
return $this->index;
public function valid()
return $this->valid;
public function rewind()
if ($this->reader->nodeType !== XMLReader::NONE) {
throw new BadMethodCallException('Reader can not be rewound');
$this->index = 0;
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.