Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.49% |
33 / 41 |
|
60.00% |
3 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ArcadiaMailGame | |
80.49% |
33 / 41 |
|
60.00% |
3 / 5 |
15.46 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| __set | |
50.00% |
2 / 4 |
|
0.00% |
0 / 1 |
6.00 | |||
| fill | |
25.00% |
2 / 8 |
|
0.00% |
0 / 1 |
21.19 | |||
| send | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
| jsonSerialize | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace LDC\LDCCRM\Models; |
| 4 | |
| 5 | use LDC\LDCCRM\Enums\ApiStatus; |
| 6 | use LDC\LDCCRM\Enums\ArcadiaOrderType; |
| 7 | use LDC\LDCCRM\Utils; |
| 8 | |
| 9 | /** |
| 10 | * This class represents the customer info with |
| 11 | * the account validation status |
| 12 | * |
| 13 | * @property integer $operation The arcadia operation code |
| 14 | * Validate: int |
| 15 | * Required |
| 16 | * |
| 17 | * @property string|null $email Must be a rfc valid email on a valid domain name |
| 18 | * @property string|null $firstname The account first name |
| 19 | * @property string|null $lastname The account last name |
| 20 | * @property string|null $phone The account phone |
| 21 | * @property string|null $address The account address (street number, name, build, flat number) |
| 22 | * @property string|null $address2 The account phone (address complement) |
| 23 | * @property string|null $city The account city name |
| 24 | * @property string|null $postcode The account city postcode |
| 25 | * |
| 26 | * @property integer|null $support_code The arcadia support code |
| 27 | * @property string|null $label_type_support The arcadia type support label |
| 28 | * @property string|null $order_date The arcadia order date 'yyyy-mm-dd HH:ii:ss' |
| 29 | * @property string|null $code_unique The arcadia code unique |
| 30 | * @property string|null $code_on_pack The arcadia code on pack |
| 31 | * |
| 32 | * @category Api Models |
| 33 | * @package LDCCrmClient |
| 34 | * @subpackage models |
| 35 | * @author Jérémy Munsch <jeremy.munsch@ldc.fr> |
| 36 | */ |
| 37 | class ArcadiaMailGame extends ClientModel |
| 38 | { |
| 39 | /** |
| 40 | * An RFC Valid Email |
| 41 | * |
| 42 | * Validate: rfc,dns,spoof,filter |
| 43 | * |
| 44 | * Required |
| 45 | * Min length N/A |
| 46 | * Max length 255 |
| 47 | * Field Type varchar |
| 48 | * |
| 49 | * @var string|null |
| 50 | */ |
| 51 | private ?string $email = null; |
| 52 | |
| 53 | /** |
| 54 | * First name |
| 55 | * |
| 56 | * Required |
| 57 | * Min length 2 |
| 58 | * Max length 255 |
| 59 | * Field Type varchar |
| 60 | * |
| 61 | * @var string|null |
| 62 | */ |
| 63 | private ?string $firstname = null; |
| 64 | |
| 65 | /** |
| 66 | * Last name |
| 67 | * |
| 68 | * Required |
| 69 | * Min length 2 |
| 70 | * Max length 255 |
| 71 | * Field Type varchar |
| 72 | * |
| 73 | * @var string|null |
| 74 | */ |
| 75 | private ?string $lastname = null; |
| 76 | |
| 77 | /** |
| 78 | * The user phone |
| 79 | * |
| 80 | * Validate: sometimes,string |
| 81 | * |
| 82 | * Required |
| 83 | * Min length NA |
| 84 | * Max length 255 |
| 85 | * Field Type varchar |
| 86 | * |
| 87 | * @var string|null |
| 88 | */ |
| 89 | private ?string $phone = null; |
| 90 | |
| 91 | /** |
| 92 | * The user address (street number, name, etc) |
| 93 | * |
| 94 | * Validate: sometimes,string |
| 95 | * |
| 96 | * Min length NA |
| 97 | * Max length 255 |
| 98 | * Field Type varchar |
| 99 | * |
| 100 | * @var string|null |
| 101 | */ |
| 102 | private ?string $address = null; |
| 103 | |
| 104 | /** |
| 105 | * The user address 2nd part (street number, name, more, etc) |
| 106 | * |
| 107 | * Validate: sometimes,string |
| 108 | * |
| 109 | * Min length NA |
| 110 | * Max length 255 |
| 111 | * Field Type varchar |
| 112 | * |
| 113 | * @var string|null |
| 114 | */ |
| 115 | private ?string $address2 = null; |
| 116 | |
| 117 | /** |
| 118 | * The user address city |
| 119 | * |
| 120 | * Validate: sometimes,string |
| 121 | * |
| 122 | * Min length NA |
| 123 | * Max length 255 |
| 124 | * Field Type varchar |
| 125 | * |
| 126 | * @var string|null |
| 127 | */ |
| 128 | private ?string $city = null; |
| 129 | |
| 130 | /** |
| 131 | * The user address postcode |
| 132 | * |
| 133 | * Validate: string |
| 134 | * |
| 135 | * Required |
| 136 | * Min length NA |
| 137 | * Max length 255 |
| 138 | * Field Type varchar |
| 139 | * |
| 140 | * @var string|null |
| 141 | */ |
| 142 | private ?string $postcode = null; |
| 143 | |
| 144 | /** |
| 145 | * The arcadia operation code |
| 146 | * |
| 147 | * Validate: int |
| 148 | * |
| 149 | * Required |
| 150 | * |
| 151 | * @var integer|null |
| 152 | */ |
| 153 | private ?int $operation = null; |
| 154 | |
| 155 | /** |
| 156 | * The arcadia support code |
| 157 | * |
| 158 | * Validate: int |
| 159 | * |
| 160 | * Required |
| 161 | * |
| 162 | * @var integer|null |
| 163 | */ |
| 164 | private ?int $support_code = null; |
| 165 | |
| 166 | /** |
| 167 | * The arcadia type support label |
| 168 | * |
| 169 | * Validate: string |
| 170 | * |
| 171 | * Required |
| 172 | * |
| 173 | * @var string|null |
| 174 | */ |
| 175 | private ?string $label_type_support = null; |
| 176 | |
| 177 | /** |
| 178 | * The arcadia order date |
| 179 | * |
| 180 | * Validate: date |
| 181 | * |
| 182 | * Required |
| 183 | * |
| 184 | * @var string|null |
| 185 | */ |
| 186 | private ?string $order_date = null; |
| 187 | |
| 188 | /** |
| 189 | * The arcadia code unique |
| 190 | * |
| 191 | * Validate: string |
| 192 | * |
| 193 | * Required |
| 194 | * |
| 195 | * @var string|null |
| 196 | */ |
| 197 | private ?string $code_unique = null; |
| 198 | |
| 199 | /** |
| 200 | * The arcadia code on pack |
| 201 | * |
| 202 | * Validate: sometimes |
| 203 | * |
| 204 | * Required |
| 205 | * |
| 206 | * @var string|null |
| 207 | */ |
| 208 | private ?string $code_on_pack = null; |
| 209 | |
| 210 | /** |
| 211 | * The crm customer fields |
| 212 | * |
| 213 | * @var array |
| 214 | */ |
| 215 | protected array $modelFields = [ |
| 216 | 'email', |
| 217 | 'firstname', |
| 218 | 'lastname', |
| 219 | 'phone', |
| 220 | 'address', |
| 221 | 'address2', |
| 222 | 'city', |
| 223 | 'postcode', |
| 224 | 'operation', |
| 225 | 'support_code', |
| 226 | 'label_type_support', |
| 227 | 'order_date', |
| 228 | 'code_unique', |
| 229 | 'code_on_pack', |
| 230 | ]; |
| 231 | |
| 232 | /** |
| 233 | * Validation rules |
| 234 | * |
| 235 | * @var array |
| 236 | */ |
| 237 | protected static array $validation = [ |
| 238 | 'email' => 'required|email', |
| 239 | 'firstname' => 'required|string|min:2|max:255', |
| 240 | 'lastname' => 'required|string|min:2|max:255', |
| 241 | 'phone' => 'sometimes|string|min:10|max:255', |
| 242 | 'address' => 'sometimes|string|max:255', |
| 243 | 'address2' => 'sometimes|string|max:255', |
| 244 | 'city' => 'sometimes|string|max:255', |
| 245 | 'postcode' => 'sometimes|string|max:255', |
| 246 | 'operation' => 'required|int', |
| 247 | 'support_code' => 'required|int', |
| 248 | 'label_type_support' => 'required|string|min:2|max:255', |
| 249 | 'order_date' => 'required|date_format:Y/m/d H:i:s', |
| 250 | 'code_unique' => 'required|string', |
| 251 | 'code_on_pack' => 'sometimes|string' |
| 252 | ]; |
| 253 | |
| 254 | /** |
| 255 | * ArcadiaMailGame |
| 256 | * |
| 257 | * @param array $properties |
| 258 | * @throws \LDC\LDCCRM\Exceptions\ValidationException If a field could not be validated. |
| 259 | */ |
| 260 | public function __construct(array $properties = []) |
| 261 | { |
| 262 | parent::__construct(); |
| 263 | $this->fill($properties); |
| 264 | return $this; |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Set prop |
| 269 | * |
| 270 | * @param string $field |
| 271 | * @param mixed $value |
| 272 | * @return void |
| 273 | * @throws \TypeError If the field has an incorrect value. |
| 274 | * @throws \LDC\LDCCRM\Exceptions\AccessError If trying to set a value on a unknown property. |
| 275 | */ |
| 276 | public function __set(string $field, mixed $value): void |
| 277 | { |
| 278 | if ($field === 'state_order') { |
| 279 | $value = (\is_object($value) and |
| 280 | get_class($value) === ArcadiaOrderType::class) ? $value->value() : $value; |
| 281 | } |
| 282 | parent::__set($field, $value); |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Fill data into this model |
| 287 | * using validation rules |
| 288 | * |
| 289 | * @param array $properties |
| 290 | * @return void |
| 291 | * @throws \LDC\LDCCRM\Exceptions\ValidationException If a field could not be validated. |
| 292 | */ |
| 293 | public function fill(array $properties) |
| 294 | { |
| 295 | if (isset($properties['state_order'])) { |
| 296 | try { |
| 297 | $properties['state_order'] = (\is_object($properties['state_order']) and |
| 298 | get_class($properties['state_order']) === ArcadiaOrderType::class) ? |
| 299 | $properties['state_order']->value : (ctype_digit($properties['state_order']) ? |
| 300 | (int)$properties['state_order'] : $properties['state_order']); |
| 301 | } catch (\TypeError | \BadMethodCallException) { |
| 302 | // * Cast anyway |
| 303 | $properties['state_order'] = (int)$properties['state_order']; |
| 304 | } |
| 305 | } |
| 306 | parent::fill($properties); |
| 307 | } |
| 308 | |
| 309 | // * PUBLIC METHODS |
| 310 | |
| 311 | /** |
| 312 | * Send The actual mail |
| 313 | * |
| 314 | * @return boolean true if succeeded |
| 315 | * @throws \LDC\LDCCRM\Exceptions\CrmException If an error occurs on server side or on getting response. |
| 316 | * @throws \LDC\LDCCRM\Exceptions\ApiErrorException If any error or \LDC\LDCCRM\Enums\ApiError occurs. |
| 317 | * Possibles are : - validationFailed, If provided data is wrong(CRM side). |
| 318 | */ |
| 319 | public function send(): bool |
| 320 | { |
| 321 | $this->validateAllValues(); |
| 322 | static::setUpApiInterface(); |
| 323 | $request = Utils::getResquest('apiV4.arcadia.outgoingMailGame', [], $this->jsonSerialize()); |
| 324 | $response = static::$apiInterface->call($request); |
| 325 | if ($status = $response->status->equals(ApiStatus::OK)) { |
| 326 | $this->updatedValues = []; |
| 327 | } |
| 328 | $this->isNew = !$status; |
| 329 | return $status; |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Serialize this object to an array |
| 334 | * |
| 335 | * @return array |
| 336 | */ |
| 337 | public function jsonSerialize() |
| 338 | { |
| 339 | return [ |
| 340 | 'deliver' => [ |
| 341 | 'email' => $this->email, |
| 342 | 'firstname' => $this->firstname, |
| 343 | 'lastname' => $this->lastname, |
| 344 | 'phone' => $this->phone, |
| 345 | 'address' => $this->address, |
| 346 | 'address2' => $this->address2, |
| 347 | 'city' => $this->city, |
| 348 | 'postcode' => $this->postcode, |
| 349 | ], |
| 350 | 'operation' => $this->operation, |
| 351 | 'support_code' => $this->support_code, |
| 352 | 'label_type_support' => $this->label_type_support, |
| 353 | 'order_date' => $this->order_date, |
| 354 | 'code_unique' => $this->code_unique, |
| 355 | 'code_on_pack' => $this->code_on_pack |
| 356 | ]; |
| 357 | } |
| 358 | } |