Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
| ContactEntity | |
0.00% |
0 / 26 |
|
0.00% |
0 / 12 |
272 | |
0.00% |
0 / 1 |
| isActive | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isInactive | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| fullName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| hasEmail | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| hasPhone | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| hasWhatsapp | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getMeta | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| setMeta | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| canUseSms | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| canUseEmail | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| canUseWhatsapp | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| toArraySafe | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Modules\ContactModule\Entities; |
| 4 | |
| 5 | use CodeIgniter\Entity\Entity; |
| 6 | |
| 7 | class ContactEntity extends Entity |
| 8 | { |
| 9 | protected $attributes = [ |
| 10 | |
| 11 | /** |
| 12 | * ========================= |
| 13 | * IDENTITÉ |
| 14 | * ========================= |
| 15 | */ |
| 16 | 'id' => null, |
| 17 | 'type' => null, |
| 18 | 'name' => null, |
| 19 | 'email' => null, |
| 20 | 'phone' => null, |
| 21 | 'whatsapp' => null, |
| 22 | 'company' => null, |
| 23 | 'job_title' => null, |
| 24 | 'status' => 'active', |
| 25 | |
| 26 | /** |
| 27 | * ========================= |
| 28 | * CANAUX |
| 29 | * ========================= |
| 30 | */ |
| 31 | 'sms_enabled' => 1, |
| 32 | 'email_enabled' => 1, |
| 33 | 'whatsapp_enabled' => 0, |
| 34 | |
| 35 | /** |
| 36 | * ========================= |
| 37 | * MÉTADATA FLEXIBLE |
| 38 | * ========================= |
| 39 | */ |
| 40 | 'metadata' => [], |
| 41 | ]; |
| 42 | |
| 43 | protected $casts = [ |
| 44 | 'id' => 'integer', |
| 45 | 'sms_enabled' => 'boolean', |
| 46 | 'email_enabled' => 'boolean', |
| 47 | 'whatsapp_enabled'=> 'boolean', |
| 48 | 'metadata' => 'json', |
| 49 | ]; |
| 50 | |
| 51 | /** |
| 52 | * ========================= |
| 53 | * HELPERS MÉTIER |
| 54 | * ========================= |
| 55 | */ |
| 56 | |
| 57 | public function isActive(): bool |
| 58 | { |
| 59 | return $this->attributes['status'] === 'active'; |
| 60 | } |
| 61 | |
| 62 | public function isInactive(): bool |
| 63 | { |
| 64 | return $this->attributes['status'] !== 'active'; |
| 65 | } |
| 66 | |
| 67 | public function fullName(): string |
| 68 | { |
| 69 | return trim((string) $this->attributes['name']); |
| 70 | } |
| 71 | |
| 72 | public function hasEmail(): bool |
| 73 | { |
| 74 | return !empty($this->attributes['email']); |
| 75 | } |
| 76 | |
| 77 | public function hasPhone(): bool |
| 78 | { |
| 79 | return !empty($this->attributes['phone']); |
| 80 | } |
| 81 | |
| 82 | public function hasWhatsapp(): bool |
| 83 | { |
| 84 | return !empty($this->attributes['whatsapp']); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * ========================= |
| 89 | * MÉTADATA ACCESS |
| 90 | * ========================= |
| 91 | */ |
| 92 | public function getMeta(?string $key = null) |
| 93 | { |
| 94 | $meta = $this->attributes['metadata'] ?? []; |
| 95 | |
| 96 | if ($key === null) { |
| 97 | return $meta; |
| 98 | } |
| 99 | |
| 100 | return $meta[$key] ?? null; |
| 101 | } |
| 102 | |
| 103 | public function setMeta(string $key, $value): self |
| 104 | { |
| 105 | $meta = $this->attributes['metadata'] ?? []; |
| 106 | |
| 107 | $meta[$key] = $value; |
| 108 | |
| 109 | $this->attributes['metadata'] = $meta; |
| 110 | |
| 111 | return $this; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * ========================= |
| 116 | * CANAUX DISPONIBLES |
| 117 | * ========================= |
| 118 | */ |
| 119 | public function canUseSms(): bool |
| 120 | { |
| 121 | return (bool) $this->sms_enabled && $this->hasPhone(); |
| 122 | } |
| 123 | |
| 124 | public function canUseEmail(): bool |
| 125 | { |
| 126 | return (bool) $this->email_enabled && $this->hasEmail(); |
| 127 | } |
| 128 | |
| 129 | public function canUseWhatsapp(): bool |
| 130 | { |
| 131 | return (bool) $this->whatsapp_enabled && $this->hasWhatsapp(); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * ========================= |
| 136 | * EXPORT SIMPLE (API / SMS) |
| 137 | * ========================= |
| 138 | */ |
| 139 | public function toArraySafe(): array |
| 140 | { |
| 141 | return [ |
| 142 | 'id' => $this->id, |
| 143 | 'type' => $this->type, |
| 144 | 'name' => $this->name, |
| 145 | 'email' => $this->email, |
| 146 | 'phone' => $this->phone, |
| 147 | 'company' => $this->company, |
| 148 | 'status' => $this->status, |
| 149 | ]; |
| 150 | } |
| 151 | } |