| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Framework\Receipts\Properties; |
| 4 |
|
| 5 |
use Give\Framework\Support\Contracts\Arrayable; |
| 6 |
|
| 7 |
use function array_map; |
| 8 |
use function array_merge; |
| 9 |
|
| 10 |
class ReceiptDetailCollection implements Arrayable |
| 11 |
{ |
| 12 |
/** |
| 13 |
* @var ReceiptDetail[] |
| 14 |
*/ |
| 15 |
protected $receiptDetails; |
| 16 |
|
| 17 |
/** |
| 18 |
* @since 3.0.0 |
| 19 |
* |
| 20 |
* @param ReceiptDetail[] $receiptDetails |
| 21 |
*/ |
| 22 |
public function __construct(array $receiptDetails = []) |
| 23 |
{ |
| 24 |
$this->receiptDetails = $receiptDetails; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* @since 3.0.0 |
| 29 |
* |
| 30 |
* @param ReceiptDetail $receiptDetail |
| 31 |
* @return void |
| 32 |
*/ |
| 33 |
public function addDetail(ReceiptDetail $receiptDetail) |
| 34 |
{ |
| 35 |
$this->receiptDetails[] = $receiptDetail; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* @since 3.0.0 |
| 40 |
* |
| 41 |
* @param ReceiptDetail[] $receiptDetails |
| 42 |
* @return void |
| 43 |
*/ |
| 44 |
public function addDetails(array $receiptDetails) |
| 45 |
{ |
| 46 |
$this->receiptDetails = array_merge($this->receiptDetails, $receiptDetails); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* @return ReceiptDetail[] |
| 51 |
*/ |
| 52 |
public function getDetails(): array |
| 53 |
{ |
| 54 |
return $this->receiptDetails; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* @since 3.0.0 |
| 59 |
*/ |
| 60 |
public function toArray(): array |
| 61 |
{ |
| 62 |
return array_map(static function (ReceiptDetail $receiptDetail) { |
| 63 |
return $receiptDetail->toArray(); |
| 64 |
}, $this->receiptDetails); |
| 65 |
} |
| 66 |
} |
| 67 |
|