diff --git a/src/DB.php b/src/DB.php index 9df07b6..fe26b08 100644 --- a/src/DB.php +++ b/src/DB.php @@ -463,14 +463,13 @@ public function fetchPretty(DataRulesInterface $rules): ?array */ public function fetchAsCollection(): ?DataCollectionInterface { - $this->run(); - if ($this->hasStatement()) { - $this->getStatement()->setFetchMode(PDO::FETCH_ASSOC); - $data = $this->getStatement()->fetchAll(); - $this->setStatement(false); - return new DataCollection($data); + $data = $this->fetch(); + + if(!is_array($data)){ + return null; } - return null; + + return new DataCollection($data); } /** @@ -518,10 +517,10 @@ public function data($data): self * Optimize data, Validate and set data to be inserted into the database. * * @param mixed $data The data to be inserted. - * + * @param DataRulesInterface $rules define rules using DataRulesInterface. * @throws DataValidatorException If the data is not valid. */ - public function prettyData($data, callable $rules) + public function prettyData($data, DataRulesInterface $rules) { $data = (new DataOptimizer($data))->optimize($rules); $this->data($data);