Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| ConsentType | |
100.00% |
7 / 7 |
|
100.00% |
7 / 7 |
8 | |
100.00% |
1 / 1 |
| requiredTypes | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| optionalTypes | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| allTypes | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isValid | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isOptional | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isValidSource | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| actionFor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Domain\Consent\Data; |
| 6 | |
| 7 | /** |
| 8 | * Catalog of TCPA consent identifiers (FSC-87). |
| 9 | * |
| 10 | * Mirrors the CHECK constraints on consent_records. When types/actions/sources |
| 11 | * change, update both this class and the constraints via a migration. |
| 12 | * |
| 13 | * - transactional: required to operate an account (service/security/account |
| 14 | * messages). Captured at registration; shown read-only afterwards. |
| 15 | * - sms / automated_calls: optional marketing-capable channels the investor can |
| 16 | * grant or revoke at any time. |
| 17 | */ |
| 18 | final class ConsentType |
| 19 | { |
| 20 | public const string TRANSACTIONAL = 'transactional'; |
| 21 | public const string SMS = 'sms'; |
| 22 | public const string AUTOMATED_CALLS = 'automated_calls'; |
| 23 | |
| 24 | public const string ACTION_GRANTED = 'granted'; |
| 25 | public const string ACTION_REVOKED = 'revoked'; |
| 26 | |
| 27 | public const string SOURCE_REGISTRATION = 'registration'; |
| 28 | public const string SOURCE_SETTINGS = 'settings'; |
| 29 | |
| 30 | /** |
| 31 | * Consent required as a condition of holding an account. |
| 32 | * |
| 33 | * @return list<string> |
| 34 | */ |
| 35 | public static function requiredTypes(): array |
| 36 | { |
| 37 | return [self::TRANSACTIONAL]; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Optional consents the investor can grant/revoke after registration. |
| 42 | * |
| 43 | * @return list<string> |
| 44 | */ |
| 45 | public static function optionalTypes(): array |
| 46 | { |
| 47 | return [self::SMS, self::AUTOMATED_CALLS]; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * @return list<string> |
| 52 | */ |
| 53 | public static function allTypes(): array |
| 54 | { |
| 55 | return [...self::requiredTypes(), ...self::optionalTypes()]; |
| 56 | } |
| 57 | |
| 58 | public static function isValid(string $type): bool |
| 59 | { |
| 60 | return in_array($type, self::allTypes(), true); |
| 61 | } |
| 62 | |
| 63 | public static function isOptional(string $type): bool |
| 64 | { |
| 65 | return in_array($type, self::optionalTypes(), true); |
| 66 | } |
| 67 | |
| 68 | public static function isValidSource(string $source): bool |
| 69 | { |
| 70 | return in_array($source, [self::SOURCE_REGISTRATION, self::SOURCE_SETTINGS], true); |
| 71 | } |
| 72 | |
| 73 | public static function actionFor(bool $granted): string |
| 74 | { |
| 75 | return $granted ? self::ACTION_GRANTED : self::ACTION_REVOKED; |
| 76 | } |
| 77 | } |