Skip to content

Commit

Permalink
fix fetchAsCollection method to return correct type (?DataCollectionI…
Browse files Browse the repository at this point in the history
…nterface),update prettyData to respect DBInterface
  • Loading branch information
BMTmohammedtaha committed Dec 6, 2023
1 parent 21592d9 commit 51e0194
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 51e0194

Please sign in to comment.