Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

AgingBucketDTO.php 913B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\DTO;
  3. use App\Contracts\MoneyFormattableDTO;
  4. readonly class AgingBucketDTO implements MoneyFormattableDTO
  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. }