Merge branch 'develop' into 'master'

Develop

See merge request ldc-web/projets/crm-client!14
This commit is contained in:
noah.lancien 2025-09-16 11:07:23 +00:00
commit 9aa66a8b3f
14 changed files with 47 additions and 53 deletions

View file

@ -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

View file

@ -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",

View file

@ -27,8 +27,7 @@
<rule ref="Generic.Files.LineLength"/>
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
<rule ref="Generic.Formatting.MultipleStatementAlignment"/>
<rule ref="Generic.Formatting.NoSpaceAfterCast"/>
<rule ref="Generic.Functions.CallTimePassByReference"/>
<rule ref="Generic.Formatting.SpaceAfterCast"/>
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
<rule ref="Generic.Metrics.CyclomaticComplexity"/>
<rule ref="Generic.Metrics.NestingLevel"/>
@ -42,9 +41,7 @@
<rule ref="Generic.Strings.UnnecessaryStringConcat"/>
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
<rule ref="Generic.WhiteSpace.ScopeIndent"/>
<rule ref="MySource.PHP.EvalObjectFactory"/>
<rule ref="MySource.PHP.GetRequestData"/>
<rule ref="MySource.PHP.AjaxNullComparison"/>
<rule ref="Generic.WhiteSpace.LanguageConstructSpacing"/>
<rule ref="PEAR.Classes.ClassDeclaration"/>
<rule ref="PEAR.Commenting.InlineComment"/>
<rule ref="PSR1.Classes.ClassDeclaration"/>
@ -77,7 +74,6 @@
<rule ref="Squiz.Scope.MemberVarScope"/>
<rule ref="Squiz.Scope.MethodScope"/>
<rule ref="Squiz.Scope.StaticThisUsage"/>
<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing"/>
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing"/>
<rule ref="Squiz.WhiteSpace.MemberVarSpacing">
<properties>

View file

@ -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)
{

View file

@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -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':

View file

@ -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);

View file

@ -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);

View file

@ -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

View file

@ -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');
}

View file

@ -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);

View file

@ -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.