CredentialResponse.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * Copyright (C) 2013 Mailgun
  5. *
  6. * This software may be modified and distributed under the terms
  7. * of the MIT license. See the LICENSE file for details.
  8. */
  9. namespace Mailgun\Model\Domain;
  10. use Mailgun\Model\ApiResponse;
  11. /**
  12. * @author Sean Johnson <sean@mailgun.com>
  13. */
  14. final class CredentialResponse implements ApiResponse
  15. {
  16. private int $totalCount;
  17. private $items;
  18. public static function create(array $data): self
  19. {
  20. $items = [];
  21. if (isset($data['items'])) {
  22. foreach ($data['items'] as $item) {
  23. $items[] = CredentialResponseItem::create($item);
  24. }
  25. }
  26. if (isset($data['total_count'])) {
  27. $count = (int) $data['total_count'];
  28. } else {
  29. $count = count($items);
  30. }
  31. $model = new self();
  32. $model->totalCount = $count;
  33. $model->items = $items;
  34. return $model;
  35. }
  36. private function __construct()
  37. {
  38. }
  39. /**
  40. * @return int
  41. */
  42. public function getTotalCount(): int
  43. {
  44. return $this->totalCount;
  45. }
  46. /**
  47. * @return CredentialResponseItem[]
  48. */
  49. public function getCredentials(): array
  50. {
  51. return $this->items;
  52. }
  53. }