From 664dd850a238507617cb296e44122bbaadad23d9 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Thu, 28 Aug 2025 16:41:39 +0200 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=F0=9F=90=9B=20update=20claim=20file?= =?UTF-8?q?=20validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Models/Claim.php | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/Models/Claim.php b/src/Models/Claim.php index 13be2da..c2cd34a 100644 --- a/src/Models/Claim.php +++ b/src/Models/Claim.php @@ -2,7 +2,6 @@ namespace LDC\LDCCRM\Models; -use Illuminate\Http\UploadedFile; use LDC\LDCCRM\CrmApiV4; use LDC\LDCCRM\Enums\ApiStatus; use LDC\LDCCRM\Utils; @@ -28,7 +27,7 @@ abstract class Claim extends ClientModel 'address' => 'sometimes|nullable|string|max:255', 'city' => 'sometimes|nullable|string|min:2|max:255', 'postcode' => 'sometimes|nullable|string', - 'file' => 'sometimes|nullable|max:5120', + 'file' => 'sometimes|nullable|string', 'message' => 'required|string|min:3', 'brand_id' => 'required|int|min:1', 'subject_id' => 'required|int|min:1', @@ -38,16 +37,16 @@ abstract class Claim extends ClientModel /** * Set new claim. * - * @param string $last_name - * @param string $first_name - * @param string $email - * @param string $message - * @param integer $brand_id - * @param integer $subject_id - * @param string|null $address - * @param string|null $city - * @param string|null $postcode - * @param UploadedFile|string|null $file + * @param string $last_name + * @param string $first_name + * @param string $email + * @param string $message + * @param integer $brand_id + * @param integer $subject_id + * @param string|null $address + * @param string|null $city + * @param string|null $postcode + * @param string|null $file * @return boolean True if succeeded. * @throws \LDC\LDCCRM\Exceptions\ValidationException If a field could not be validated. * @throws \LDC\LDCCRM\Exceptions\CrmException If an error occurs on server side or on getting response. @@ -64,7 +63,7 @@ abstract class Claim extends ClientModel #[\SensitiveParameter] ?string $address = null, #[\SensitiveParameter] ?string $city = null, #[\SensitiveParameter] ?string $postcode = null, - #[\SensitiveParameter] UploadedFile|string|null $file = null, + #[\SensitiveParameter] string|null $file = null, ): bool { // @phpcs:enable $params = compact( @@ -77,12 +76,9 @@ abstract class Claim extends ClientModel 'address', 'city', 'postcode', + 'file', ); - $params['file'] = ($file instanceof UploadedFile) - ? base64_encode(file_get_contents($file->getRealPath())) - : $file; - // Add customer relation if exist. $crmCustomer = (new CrmApiV4())->getCustomer($email); $params['customer_id'] = $crmCustomer; From a7d7436b10d01ac4274dbee9bca6918726f9c803 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Thu, 28 Aug 2025 16:41:48 +0200 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=F0=9F=9A=A8=20resolve=20phpcs=20err?= =?UTF-8?q?ors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpcs.xml | 8 ++------ src/Exceptions/ApiErrorException.php | 6 +++--- src/Models/ArcadiaMailDefault.php | 6 +++--- src/Models/ArcadiaMailGame.php | 6 +++--- src/Models/ClientModel.php | 4 ++-- src/Models/Customer.php | 4 ++-- src/Models/Question.php | 6 +++--- src/Traits/BaseEnum.php | 4 ++-- src/Transport/Response.php | 2 +- src/Utils.php | 14 +++++++------- src/WordPress/WPCrm.php | 4 +--- 11 files changed, 29 insertions(+), 35 deletions(-) diff --git a/phpcs.xml b/phpcs.xml index accfa4a..96ba44b 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -27,8 +27,7 @@ - - + @@ -42,9 +41,7 @@ - - - + @@ -77,7 +74,6 @@ - diff --git a/src/Exceptions/ApiErrorException.php b/src/Exceptions/ApiErrorException.php index e1b6aca..0aa055f 100644 --- a/src/Exceptions/ApiErrorException.php +++ b/src/Exceptions/ApiErrorException.php @@ -51,9 +51,9 @@ class ApiErrorException extends \RuntimeException * Create a new exception base on ApiError enum. * * @param \LDC\LDCCRM\Enums\ApiError $error - * @param integer $httpCode - * @param string $message - * @param \Throwable|null $previous + * @param integer $httpCode + * @param string $message + * @param \Throwable|null $previous */ public function __construct(ApiError $error, int $httpCode = 400, string $message = '', \Throwable $previous = null) { diff --git a/src/Models/ArcadiaMailDefault.php b/src/Models/ArcadiaMailDefault.php index c9ca75f..4fcac45 100644 --- a/src/Models/ArcadiaMailDefault.php +++ b/src/Models/ArcadiaMailDefault.php @@ -327,11 +327,11 @@ class ArcadiaMailDefault extends ClientModel try { $properties['state_order'] = (\is_object($properties['state_order']) and get_class($properties['state_order']) === ArcadiaOrderType::class) ? - $properties['state_order']->value() : (ctype_digit((string)$properties['state_order']) ? - (int)$properties['state_order'] : $properties['state_order']); + $properties['state_order']->value() : (ctype_digit((string) $properties['state_order']) ? + (int) $properties['state_order'] : $properties['state_order']); } catch (\TypeError | \BadMethodCallException) { // * Cast anyway - $properties['state_order'] = (int)$properties['state_order']; + $properties['state_order'] = (int) $properties['state_order']; } } parent::fill($properties); diff --git a/src/Models/ArcadiaMailGame.php b/src/Models/ArcadiaMailGame.php index aa180e0..b855fa7 100644 --- a/src/Models/ArcadiaMailGame.php +++ b/src/Models/ArcadiaMailGame.php @@ -296,11 +296,11 @@ class ArcadiaMailGame extends ClientModel try { $properties['state_order'] = (\is_object($properties['state_order']) and get_class($properties['state_order']) === ArcadiaOrderType::class) ? - $properties['state_order']->value : (ctype_digit((string)$properties['state_order']) ? - (int)$properties['state_order'] : $properties['state_order']); + $properties['state_order']->value : (ctype_digit((string) $properties['state_order']) ? + (int) $properties['state_order'] : $properties['state_order']); } catch (\TypeError | \BadMethodCallException) { // * Cast anyway - $properties['state_order'] = (int)$properties['state_order']; + $properties['state_order'] = (int) $properties['state_order']; } } parent::fill($properties); diff --git a/src/Models/ClientModel.php b/src/Models/ClientModel.php index ae3b7f1..5402d2d 100644 --- a/src/Models/ClientModel.php +++ b/src/Models/ClientModel.php @@ -146,7 +146,7 @@ abstract class ClientModel implements \JsonSerializable $type = $this->getPropType($field); // * Force boolean if ($type === 'bool') { - $value = (\is_int($value) and ($value === 1 or $value === 0)) ? (bool)$value : $value; + $value = (\is_int($value) and ($value === 1 or $value === 0)) ? (bool) $value : $value; } if (!is_null($value) and !$this->checkFieldType($type, $value)) { throw new ValidationException("Wrong type for $field"); @@ -270,7 +270,7 @@ abstract class ClientModel implements \JsonSerializable case '\\' . ArcadiaOrderType::class: return $checkValueIsEnum(\ltrim($type, '\\'), $value); case 'boolean': - return \is_bool(\is_int($value) ? (bool)$value : $value); + return \is_bool(\is_int($value) ? (bool) $value : $value); case 'array': return \is_array($value); case 'string': diff --git a/src/Models/Customer.php b/src/Models/Customer.php index 8c819d2..3b3bb8b 100644 --- a/src/Models/Customer.php +++ b/src/Models/Customer.php @@ -356,10 +356,10 @@ class Customer extends ClientModel $properties['country'] = (\is_object($properties['country']) and get_class($properties['country']) === Country::class) ? $properties['country']->value : (is_numeric(trim($properties['country'])) ? - (int)$properties['country'] : $properties['country']); + (int) $properties['country'] : $properties['country']); } catch (TypeError | \BadMethodCallException $e) { // * Cast anyway - $properties['country'] = (int)$properties['country']; + $properties['country'] = (int) $properties['country']; } } parent::fill($properties); diff --git a/src/Models/Question.php b/src/Models/Question.php index 00902a4..521142a 100644 --- a/src/Models/Question.php +++ b/src/Models/Question.php @@ -154,11 +154,11 @@ class Question extends ClientModel try { $properties['type'] = (\is_object($properties['type']) and get_class($properties['type']) === QuestionType::class) ? - $properties['type']->value : (ctype_digit((string)$properties['type']) ? - (int)$properties['type'] : $properties['type']); + $properties['type']->value : (ctype_digit((string) $properties['type']) ? + (int) $properties['type'] : $properties['type']); } catch (\TypeError | \BadMethodCallException) { // * Cast anyway - $properties['type'] = (int)$properties['type']; + $properties['type'] = (int) $properties['type']; } } parent::fill($properties); diff --git a/src/Traits/BaseEnum.php b/src/Traits/BaseEnum.php index d7fd971..aef1296 100644 --- a/src/Traits/BaseEnum.php +++ b/src/Traits/BaseEnum.php @@ -113,7 +113,7 @@ trait BaseEnum } $baseArray[$index] = $elements[$enum->name]; } - $array = array_merge($array, [$enum->name => (object)$baseArray]); + $array = array_merge($array, [$enum->name => (object) $baseArray]); }, self::cases()); self::setCache('enums', $array); } //end if @@ -124,7 +124,7 @@ trait BaseEnum * Fetch enum using value. * * @param \LDC\LDCCRM\Traits\BaseEnum|integer|string $value - * @param string $field + * @param string $field * @return \LDC\LDCCRM\Traits\BaseEnum|null */ public static function make(self|int|string $value, string $field = 'value'): self|null diff --git a/src/Transport/Response.php b/src/Transport/Response.php index 50a63b1..c6bb81d 100644 --- a/src/Transport/Response.php +++ b/src/Transport/Response.php @@ -105,7 +105,7 @@ class Response // * Body should be json data. if (($decodedJson = $this->tryDecodeJson($this->body->getContents())) === false) { if (Utils::getConfig('app.env') === 'testing') { - dump((string)$this->body); + dump((string) $this->body); } throw new CrmException('The Api should have returned JSON data'); } diff --git a/src/Utils.php b/src/Utils.php index 98ba912..a757d15 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -280,7 +280,7 @@ class Utils ), 'validate' => function () use ($value, $params) { if (\is_string($value)) { - return \strlen($value) === (int)$params[0]; + return \strlen($value) === (int) $params[0]; } return false; } @@ -307,10 +307,10 @@ class Utils ), 'validate' => function () use ($value, $params) { if (\is_string($value)) { - return \strlen($value) >= (int)$params[0]; + return \strlen($value) >= (int) $params[0]; } if (\is_int($value)) { - return $value >= (int)$params[0]; + return $value >= (int) $params[0]; } return false; } @@ -337,10 +337,10 @@ class Utils ), 'validate' => function () use ($value, $params) { if (\is_string($value)) { - return \strlen($value) <= (int)$params[0]; + return \strlen($value) <= (int) $params[0]; } if (\is_int($value)) { - return $value <= (int)$params[0]; + return $value <= (int) $params[0]; } return false; } @@ -569,10 +569,10 @@ class Utils ): Request { // Convert bool to integer. $query = \array_map(function ($v) { - return is_bool($v) ? (int)$v : $v; + return is_bool($v) ? (int) $v : $v; }, $query); $data = \array_map(function ($v) { - return is_bool($v) ? (int)$v : $v; + return is_bool($v) ? (int) $v : $v; }, $data); $routes = \json_decode(\file_get_contents(__DIR__ . '/routes.json'), true); diff --git a/src/WordPress/WPCrm.php b/src/WordPress/WPCrm.php index fa41bba..ad230fb 100644 --- a/src/WordPress/WPCrm.php +++ b/src/WordPress/WPCrm.php @@ -181,7 +181,7 @@ class WPCrm public static function check() { self::bootSessionIfNeeded(); - return (bool)self::getUser(); + return (bool) self::getUser(); } /** @@ -307,8 +307,6 @@ class WPCrm * Activate the current user * * @return boolean True if the operation succeeded. - * @throws \LDC\LDCCRM\Exceptions\ValidationException If a customer's hashcode could not be validated. - * @throws \LDC\LDCCRM\Exceptions\CrmException If an error occurs on server side or on getting response. * @throws \LDC\LDCCRM\Exceptions\ApiErrorException If any error or \LDC\LDCCRM\Enums\ApiError occurs. * Possibles are : - modelNotFound, If this customer hashcode could not be found. * - customerAlreadyActive, It the customer is already activated. From 9e968e71e19bb1262802c5e24abe4b0bad584802 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Thu, 28 Aug 2025 16:41:55 +0200 Subject: [PATCH 3/3] =?UTF-8?q?chore:=20=F0=9F=94=96=20release=20v4.1.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++++ composer.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64ec449..8f4b68f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ### All notable changes to `CRM CLient V4` will be documented in this file. +# version 4.1.4 +- Changed: update claim file validation +- Changed: resolve phpcs errors + # version 4.1.3 - Added: client tests for registering a claim diff --git a/composer.json b/composer.json index 95319b5..0590a57 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "library", "description": "LDC CRM Client V4", "license": "MIT", - "version": "4.1.3", + "version": "4.1.4", "authors": [ { "name": "Jérémy Munsch",