選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

AgingBucketDTO.php 911B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\DTO;
  3. use App\Contracts\BalanceFormattable;
  4. readonly class AgingBucketDTO implements BalanceFormattable
  5. {
  6. /**
  7. * @param array<string, string> $periods
  8. */
  9. public function __construct(
  10. public string $current,
  11. public array $periods,
  12. public string $overPeriods,
  13. public string $total,
  14. ) {}
  15. public static function fromArray(array $balances): static
  16. {
  17. $periods = [];
  18. // Extract all period balances
  19. foreach ($balances as $key => $value) {
  20. if (str_starts_with($key, 'period_')) {
  21. $periods[$key] = $value;
  22. unset($balances[$key]);
  23. }
  24. }
  25. return new static(
  26. current: $balances['current'],
  27. periods: $periods,
  28. overPeriods: $balances['over_periods'],
  29. total: $balances['total'],
  30. );
  31. }
  32. }