Skip to content

Commit

Permalink
Improve the checking required params
Browse files Browse the repository at this point in the history
  • Loading branch information
Esteban De la Rosa authored Jun 7, 2019
1 parent 928e0d3 commit 6c72ec0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Contracts/Api/CrudBehaviorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,24 @@ protected function processInput(array $request): array
return $request;
}

// TODO: Move it to its own class.
/**
* Given a process request return the records.
*
* @return void
*/
protected function getRecords(array $processedRequest): array
{
// TODO: Create a const with these values
$required = ['sql', 'countSql', 'bind'];

if (count(array_intersect_key(array_flip($required), $processedRequest)) != count($required)) {
throw new ArgumentCountError('Not a processed request missing any of the following params : SQL, CountSQL, Bind');
if ($diff = array_diff($required, array_keys($processedRequest))) {
throw new ArgumentCountError(
sprintf(
'Request no processed. Missing any of the following params : %s.',
implode(', ', $diff)
)
);
}

$results = new SimpleRecords(
Expand Down Expand Up @@ -140,6 +147,7 @@ protected function processIndex()
$processedRequest = $this->processRequest($this->request);
$records = $this->getRecords($processedRequest);


//get the results and append its relationships
$results = $this->appendRelationshipsToResult($this->request, $records['results']);

Expand Down

0 comments on commit 6c72ec0

Please sign in to comment.