First full implementation of new storage routine.

This commit is contained in:
James Cole
2019-03-17 17:05:16 +01:00
parent 6bd2b4f288
commit 200a4b18a8
19 changed files with 958 additions and 674 deletions

View File

@@ -86,6 +86,45 @@ class BillRepository implements BillRepositoryInterface
return $this->user->bills()->find($billId);
}
/**
* Find bill by parameters.
*
* @param Bill|null $bill
* @param int|null $billId
* @param string|null $billName
*
* @return Bill|null
*/
public function findBill(?Bill $bill, ?int $billId, ?string $billName): ?Bill
{
Log::debug('Searching for bill information.');
if ($bill instanceof Bill && $bill->user_id === $this->user->id) {
Log::debug(sprintf('Bill object in parameters, will return Bill #%d', $bill->id));
return $bill;
}
if (null !== $billId) {
$searchResult = $this->find((int)$billId);
if (null !== $searchResult) {
Log::debug(sprintf('Found bill based on #%d, will return it.', $billId));
return $searchResult;
}
}
if (null !== $billName) {
$searchResult = $this->findByName((string)$billName);
if (null !== $searchResult) {
Log::debug(sprintf('Found bill based on "%s", will return it.', $billName));
return $searchResult;
}
}
Log::debug('Found nothing');
return null;
}
/**
* Find a bill by name.
*