Make sure transformer accepts null dates.

This commit is contained in:
James Cole 2018-02-07 10:49:24 +01:00
parent fae7dabbc2
commit 587ad1298d
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E

View File

@ -95,6 +95,7 @@ class BillTransformer extends TransformerAbstract
public function transform(Bill $bill): array public function transform(Bill $bill): array
{ {
$paidData = $this->paidData($bill); $paidData = $this->paidData($bill);
$payDates = $this->payDates($bill);
$data = [ $data = [
'id' => (int)$bill->id, 'id' => (int)$bill->id,
'name' => $bill->name, 'name' => $bill->name,
@ -107,7 +108,7 @@ class BillTransformer extends TransformerAbstract
'automatch' => intval($bill->automatch) === 1, 'automatch' => intval($bill->automatch) === 1,
'active' => intval($bill->active) === 1, 'active' => intval($bill->active) === 1,
'attachments_count' => $bill->attachments()->count(), 'attachments_count' => $bill->attachments()->count(),
'pay_dates' => $this->payDates($bill), 'pay_dates' => $payDates,
'paid_dates' => $paidData['paid_dates'], 'paid_dates' => $paidData['paid_dates'],
'next_expected_match' => $paidData['next_expected_match'], 'next_expected_match' => $paidData['next_expected_match'],
'links' => [ 'links' => [
@ -217,6 +218,9 @@ class BillTransformer extends TransformerAbstract
*/ */
protected function payDates(Bill $bill): array protected function payDates(Bill $bill): array
{ {
if (is_null($this->start) || is_null($this->end)) {
return [];
}
$set = new Collection; $set = new Collection;
$currentStart = clone $this->start; $currentStart = clone $this->start;
while ($currentStart <= $this->end) { while ($currentStart <= $this->end) {