User.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /*
  3. * Copyright 2026 Alessandro Chiapparini <sprint_planer_web@chiapparini.org>
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * See the LICENSE file in the project root for the full license text.
  9. */
  10. declare(strict_types=1);
  11. namespace App\Domain;
  12. final class User
  13. {
  14. /**
  15. * Public label used in the UI when a user is tombstoned (R01-N23). Audit
  16. * rows keep the historical email verbatim; this constant only feeds the
  17. * live display layer (Users page, anywhere that surfaces a user object).
  18. */
  19. public const TOMBSTONE_LABEL = '(former user)';
  20. public function __construct(
  21. public readonly int $id,
  22. public readonly string $entraOid,
  23. public readonly string $email,
  24. public readonly string $displayName,
  25. public readonly bool $isAdmin,
  26. public readonly string $createdAt,
  27. public readonly ?string $lastLoginAt,
  28. public readonly ?string $tombstonedAt = null,
  29. ) {
  30. }
  31. public function isTombstoned(): bool
  32. {
  33. return $this->tombstonedAt !== null;
  34. }
  35. /** Email to display in the live UI — redacted while tombstoned. */
  36. public function publicEmail(): string
  37. {
  38. return $this->isTombstoned() ? self::TOMBSTONE_LABEL : $this->email;
  39. }
  40. /** Display name for the live UI — redacted while tombstoned. */
  41. public function publicDisplayName(): string
  42. {
  43. return $this->isTombstoned() ? self::TOMBSTONE_LABEL : $this->displayName;
  44. }
  45. /** Stable row snapshot for audit JSON. */
  46. public function toAuditSnapshot(): array
  47. {
  48. return [
  49. 'id' => $this->id,
  50. 'entra_oid' => $this->entraOid,
  51. 'email' => $this->email,
  52. 'display_name' => $this->displayName,
  53. 'is_admin' => $this->isAdmin ? 1 : 0,
  54. 'created_at' => $this->createdAt,
  55. 'last_login_at' => $this->lastLoginAt,
  56. 'tombstoned_at' => $this->tombstonedAt,
  57. ];
  58. }
  59. }