diff --git a/src/ResultSet/AbstractResultSet.php b/src/ResultSet/AbstractResultSet.php index 3911885e38..a147baecb4 100644 --- a/src/ResultSet/AbstractResultSet.php +++ b/src/ResultSet/AbstractResultSet.php @@ -25,26 +25,18 @@ abstract class AbstractResultSet implements Iterator, ResultSetInterface * if array, already buffering * @var mixed */ - protected $buffer = null; + protected $buffer; - /** - * @var null|int - */ - protected $count = null; + /** @var null|int */ + protected $count; - /** - * @var Iterator|IteratorAggregate|ResultInterface - */ - protected $dataSource = null; + /** @var Iterator|IteratorAggregate|ResultInterface */ + protected $dataSource; - /** - * @var int - */ + /** @var int */ protected $fieldCount = 0; - /** - * @var int - */ + /** @var int */ protected $position = 0; /** @@ -54,7 +46,7 @@ abstract class AbstractResultSet implements Iterator, ResultSetInterface * @return self Provides a fluent interface * @throws Exception\InvalidArgumentException */ - public function initialize($dataSource) + public function initialize($dataSource) : self { // reset buffering if (is_array($this->buffer)) { @@ -93,42 +85,33 @@ public function initialize($dataSource) return $this; } - /** - * @return self Provides a fluent interface - * @throws Exception\RuntimeException - */ - public function buffer() + public function buffer() : self { if ($this->buffer === -2) { throw new Exception\RuntimeException('Buffering must be enabled before iteration is started'); - } elseif ($this->buffer === null) { + } + + if ($this->buffer === null) { $this->buffer = []; if ($this->dataSource instanceof ResultInterface) { $this->dataSource->rewind(); } } + return $this; } - public function isBuffered() + public function isBuffered() : bool { - if ($this->buffer === -1 || is_array($this->buffer)) { - return true; - } - return false; + return $this->buffer === -1 || is_array($this->buffer); } - /** - * Get the data source used to create the result set - * - * @return null|Iterator - */ - public function getDataSource() + public function getDataSource() : ?Iterator { return $this->dataSource; } - public function getFieldCount(): int + public function getFieldCount() : int { if (null !== $this->fieldCount) { return $this->fieldCount; @@ -155,12 +138,7 @@ public function getFieldCount(): int return $this->fieldCount; } - /** - * Iterator: move pointer to next item - * - * @return void - */ - public function next() + public function next() : void { if ($this->buffer === null) { $this->buffer = -2; // implicitly disable buffering from here on @@ -171,12 +149,7 @@ public function next() $this->position++; } - /** - * Iterator: retrieve current key - * - * @return mixed - */ - public function key() + public function key() : int { return $this->position; } @@ -205,30 +178,21 @@ public function current() return is_array($data) ? $data : null; } - /** - * Iterator: is pointer valid? - * - * @return bool - */ - public function valid() + public function valid() : bool { if (is_array($this->buffer) && isset($this->buffer[$this->position])) { return true; } + if ($this->dataSource instanceof Iterator) { return $this->dataSource->valid(); - } else { - $key = key($this->dataSource); - return ($key !== null); } + + $key = key($this->dataSource); + return ($key !== null); } - /** - * Iterator: rewind - * - * @return void - */ - public function rewind() + public function rewind() : void { if (! is_array($this->buffer)) { if ($this->dataSource instanceof Iterator) { @@ -240,12 +204,7 @@ public function rewind() $this->position = 0; } - /** - * Countable: return count of rows - * - * @return int - */ - public function count() + public function count() : int { if ($this->count !== null) { return $this->count; @@ -264,7 +223,7 @@ public function count() * @return array * @throws Exception\RuntimeException if any row is not castable to an array */ - public function toArray() + public function toArray() : array { $return = []; foreach ($this as $row) { diff --git a/src/ResultSet/Exception/ExceptionInterface.php b/src/ResultSet/Exception/ExceptionInterface.php index 646aec4c88..6276bc40f1 100644 --- a/src/ResultSet/Exception/ExceptionInterface.php +++ b/src/ResultSet/Exception/ExceptionInterface.php @@ -1,12 +1,12 @@ setHydrator($hydrator ?: new $defaultHydratorClass()); - $this->setObjectPrototype(($objectPrototype) ?: new ArrayObject); + $this->setObjectPrototype($objectPrototype ?: new ArrayObject); } - /** - * Set the row object prototype - * - * @param object $objectPrototype - * @return self Provides a fluent interface - * @throws Exception\InvalidArgumentException - */ - public function setObjectPrototype($objectPrototype) + public function setObjectPrototype(object $objectPrototype) : self { - if (! is_object($objectPrototype)) { - throw new Exception\InvalidArgumentException( - 'An object must be set as the object prototype, a ' . gettype($objectPrototype) . ' was provided.' - ); - } $this->objectPrototype = $objectPrototype; return $this; } - /** - * Get the row object prototype - * - * @return object - */ - public function getObjectPrototype() + public function getObjectPrototype() : object { return $this->objectPrototype; } - /** - * Set the hydrator to use for each row object - * - * @param HydratorInterface $hydrator - * @return self Provides a fluent interface - */ - public function setHydrator(HydratorInterface $hydrator) + public function setHydrator(HydratorInterface $hydrator) : self { $this->hydrator = $hydrator; return $this; } - /** - * Get the hydrator to use for each row object - * - * @return HydratorInterface - */ - public function getHydrator() + public function getHydrator() : HydratorInterface { return $this->hydrator; } @@ -94,7 +56,7 @@ public function getHydrator() /** * Iterator: get current item * - * @return object + * @return null|array|bool */ public function current() { @@ -113,13 +75,7 @@ public function current() return $object; } - /** - * Cast result set to array of arrays - * - * @return array - * @throws Exception\RuntimeException if any row is not castable to an array - */ - public function toArray() + public function toArray() : array { $return = []; foreach ($this as $row) { diff --git a/src/ResultSet/ResultSet.php b/src/ResultSet/ResultSet.php index ebbb455c3b..f7a5d897e7 100644 --- a/src/ResultSet/ResultSet.php +++ b/src/ResultSet/ResultSet.php @@ -1,50 +1,37 @@ returnType = $returnType; @@ -52,24 +39,14 @@ public function __construct($returnType = self::TYPE_ARRAYOBJECT, $arrayObjectPr $this->returnType = self::TYPE_ARRAYOBJECT; } if ($this->returnType === self::TYPE_ARRAYOBJECT) { - $this->setArrayObjectPrototype(($arrayObjectPrototype) ?: new ArrayObject([], ArrayObject::ARRAY_AS_PROPS)); + $this->setArrayObjectPrototype($arrayObjectPrototype ?: new ArrayObject([], ArrayObject::ARRAY_AS_PROPS)); } } - /** - * Set the row object prototype - * - * @param ArrayObject $arrayObjectPrototype - * @return self Provides a fluent interface - * @throws Exception\InvalidArgumentException - */ - public function setArrayObjectPrototype($arrayObjectPrototype) + public function setArrayObjectPrototype(object $arrayObjectPrototype) : self { - if (! is_object($arrayObjectPrototype) - || ( - ! $arrayObjectPrototype instanceof ArrayObject - && ! method_exists($arrayObjectPrototype, 'exchangeArray') - ) + if (! $arrayObjectPrototype instanceof ArrayObject + && ! method_exists($arrayObjectPrototype, 'exchangeArray') ) { throw new Exception\InvalidArgumentException( 'Object must be of type ArrayObject, or at least implement exchangeArray' @@ -79,28 +56,18 @@ public function setArrayObjectPrototype($arrayObjectPrototype) return $this; } - /** - * Get the row object prototype - * - * @return ArrayObject - */ - public function getArrayObjectPrototype() + public function getArrayObjectPrototype() : ArrayObject { return $this->arrayObjectPrototype; } - /** - * Get the return type to use when returning objects from the set - * - * @return string - */ - public function getReturnType() + public function getReturnType() : string { return $this->returnType; } /** - * @return array|\ArrayObject|null + * @return array|ArrayObject|null */ public function current() { diff --git a/src/ResultSet/ResultSetInterface.php b/src/ResultSet/ResultSetInterface.php index 5891dbfc27..3474d6816f 100644 --- a/src/ResultSet/ResultSetInterface.php +++ b/src/ResultSet/ResultSetInterface.php @@ -1,12 +1,12 @@