diff --git a/phpcs.xml b/phpcs.xml
index 5604a41..c3736aa 100644
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -18,13 +18,14 @@
+
+
-
diff --git a/src/CrmApiV2.php b/src/CrmApiV2.php
index acde0a5..db6eab7 100644
--- a/src/CrmApiV2.php
+++ b/src/CrmApiV2.php
@@ -41,7 +41,7 @@ class CrmApiV2
*/
public function ping(): bool
{
- $request = Utils::getResquest('apiV2.ping');
+ $request = Utils::getResquest('apiV2.ping');
$response = self::$apiInterface->call($request);
return $response->status->equals(ApiStatus::OK());
}
diff --git a/src/Models/ArcadiaMailDefault.php b/src/Models/ArcadiaMailDefault.php
index 4c4b598..f980441 100644
--- a/src/Models/ArcadiaMailDefault.php
+++ b/src/Models/ArcadiaMailDefault.php
@@ -71,7 +71,7 @@ class ArcadiaMailDefault extends CrmClientModel
*
* @var string
*/
- private $lastname = null;
+ private $lastname = null;
/**
* The user phone
@@ -353,7 +353,7 @@ class ArcadiaMailDefault extends CrmClientModel
{
$this->validateAllValues();
static::setUpApiInterface(); // set apiInterface
- $request = Utils::getResquest('apiV2.arcadia.outgoingMailDefault', [], $this->jsonSerialize());
+ $request = Utils::getResquest('apiV2.arcadia.outgoingMailDefault', [], $this->jsonSerialize());
$response = static::$apiInterface->call($request);
if ($status = $response->status->equals(ApiStatus::OK())) {
$this->updatedValues = [];
diff --git a/src/Models/ArcadiaMailGame.php b/src/Models/ArcadiaMailGame.php
index 24bc1b1..5497d0a 100644
--- a/src/Models/ArcadiaMailGame.php
+++ b/src/Models/ArcadiaMailGame.php
@@ -73,7 +73,7 @@ class ArcadiaMailGame extends CrmClientModel
*
* @var string
*/
- private $lastname = null;
+ private $lastname = null;
/**
* The user phone
@@ -303,7 +303,7 @@ class ArcadiaMailGame extends CrmClientModel
{
$this->validateAllValues();
static::setUpApiInterface(); // set apiInterface
- $request = Utils::getResquest('apiV2.arcadia.outgoingMailGame', [], $this->jsonSerialize());
+ $request = Utils::getResquest('apiV2.arcadia.outgoingMailGame', [], $this->jsonSerialize());
$response = static::$apiInterface->call($request);
if ($status = $response->status->equals(ApiStatus::OK())) {
$this->updatedValues = [];
diff --git a/src/Models/CrmClientModel.php b/src/Models/CrmClientModel.php
index f3db46c..34d5005 100644
--- a/src/Models/CrmClientModel.php
+++ b/src/Models/CrmClientModel.php
@@ -254,9 +254,9 @@ abstract class CrmClientModel implements JsonSerializable
*/
protected function getPropType(string $property)
{
- $matches = [];
+ $matches = [];
$propReflection = new ReflectionProperty(static::class, $property);
- $docComment = $propReflection->getDocComment();
+ $docComment = $propReflection->getDocComment();
preg_match_all('/@var ([\w_\x5c]+)/', $docComment, $matches);
if (isset($matches[1][0]) and in_array($matches[1][0], [
'string', 'int', 'bool', 'array', '\\' . Country::class, '\\' . ArcadiaOrderType::class,
@@ -280,7 +280,7 @@ abstract class CrmClientModel implements JsonSerializable
$value = $value->value;
}
$refClass = new ReflectionClass(\get_class($object));
- $refProp = $refClass->getProperty($field);
+ $refProp = $refClass->getProperty($field);
$refProp->setAccessible(true);
$refProp->setValue($object, $value);
}
@@ -295,7 +295,7 @@ abstract class CrmClientModel implements JsonSerializable
protected static function getRawProperty(object $object, string $field)
{
$refClass = new ReflectionClass(\get_class($object));
- $refProp = $refClass->getProperty($field);
+ $refProp = $refClass->getProperty($field);
$refProp->setAccessible(true);
return $refProp->getValue($object);
}
diff --git a/src/Models/Customer.php b/src/Models/Customer.php
index 1f6c07a..cc9af36 100644
--- a/src/Models/Customer.php
+++ b/src/Models/Customer.php
@@ -95,7 +95,7 @@ class Customer extends CrmClientModel
*
* @var string
*/
- private $password = null;
+ private $password = null;
/**
* First name
@@ -119,7 +119,7 @@ class Customer extends CrmClientModel
*
* @var string
*/
- private $lastname = null;
+ private $lastname = null;
/**
* Birth date
@@ -386,7 +386,7 @@ class Customer extends CrmClientModel
public static function find(string $hashcode): ?self
{
static::setUpApiInterface(); // set apiInterface
- $request = Utils::getResquest('apiV2.customers.show', [
+ $request = Utils::getResquest('apiV2.customers.show', [
'customer' => $hashcode
]);
$customer = null;
@@ -432,8 +432,8 @@ class Customer extends CrmClientModel
{
$saved = false;
if ($this->isNew) {
- $saved = $this->store();
- $this->isNew = !$saved;
+ $saved = $this->store();
+ $this->isNew = !$saved;
$this->updatedValues = [];
if ($saved) {
$this->setRawProperty($this, 'password', null);
@@ -449,7 +449,7 @@ class Customer extends CrmClientModel
private function store(): bool
{
- $data = $this->validateAllValues(['hashcode', 'last_connection', 'status']);
+ $data = $this->validateAllValues(['hashcode', 'last_connection', 'status']);
$data['password'] = $this->password;
static::setUpApiInterface(); // set apiInterface
@@ -553,7 +553,7 @@ class Customer extends CrmClientModel
self::validateValue('email', $email);
static::setUpApiInterface(); // set apiInterface
- $request = Utils::getResquest('apiV2.customers.authenticate', [], [
+ $request = Utils::getResquest('apiV2.customers.authenticate', [], [
'email' => $email,
'password' => $password
]);
diff --git a/src/Models/Question.php b/src/Models/Question.php
index cb9566f..db1cda5 100644
--- a/src/Models/Question.php
+++ b/src/Models/Question.php
@@ -191,13 +191,13 @@ class Question extends CrmClientModel
$request = Utils::getResquest('apiV2.questions.index');
$response = static::$apiInterface->call($request);
- $out = [];
+ $out = [];
foreach ($response->data as $question) {
- $answers = \array_map(function ($answer) {
+ $answers = \array_map(function ($answer) {
return new Answer($answer);
}, $question['answers']);
$question['answers'] = $answers;
- $out[] = new self($question);
+ $out[] = new self($question);
}
return $out;
}
@@ -230,9 +230,9 @@ class Question extends CrmClientModel
]);
$response = static::$apiInterface->call($request);
- $out = [];
+ $out = [];
foreach ($response->data as $question) {
- $answers = \array_map(function ($answer) {
+ $answers = \array_map(function ($answer) {
return new Answer($answer);
}, $question['answers']);
$customerAnswers = \array_map(function ($answer) {
@@ -240,7 +240,7 @@ class Question extends CrmClientModel
}, $question['customerAnswers']);
unset($question['customerAnswers']);
$question['answers'] = $answers;
- $out[] = [
+ $out[] = [
'question' => new self($question),
'customerAnswers' => $customerAnswers,
];
@@ -268,13 +268,13 @@ class Question extends CrmClientModel
);
$response = static::$apiInterface->call($request);
- $out = [];
+ $out = [];
foreach ($response->data as $question) {
- $answers = \array_map(function ($answer) {
+ $answers = \array_map(function ($answer) {
return new Answer($answer);
}, $question['answers']);
$question['answers'] = $answers;
- $out[] = new self($question);
+ $out[] = new self($question);
}
return $out;
}
diff --git a/src/Models/Stats.php b/src/Models/Stats.php
index 8092194..0d815f4 100644
--- a/src/Models/Stats.php
+++ b/src/Models/Stats.php
@@ -44,7 +44,7 @@ abstract class Stats extends CrmClientModel
self::validateValue('start', $start);
self::validateValue('end', $end);
static::setUpApiInterface(); // set apiInterface
- $request = Utils::getResquest('apiV2.stats.brandStats', [], [
+ $request = Utils::getResquest('apiV2.stats.brandStats', [], [
'start' => $start,
'end' => $end
]);
@@ -71,7 +71,7 @@ abstract class Stats extends CrmClientModel
self::validateValue('start', $start);
self::validateValue('end', $end);
static::setUpApiInterface(); // set apiInterface
- $request = Utils::getResquest('apiV2.stats.questionStats', [], [
+ $request = Utils::getResquest('apiV2.stats.questionStats', [], [
'question' => $question->id,
'start' => $start,
'end' => $end
diff --git a/src/Transport/ApiInterface.php b/src/Transport/ApiInterface.php
index 7496efe..b7874ab 100644
--- a/src/Transport/ApiInterface.php
+++ b/src/Transport/ApiInterface.php
@@ -83,12 +83,12 @@ class ApiInterface
static::$memcachedPool = new MemcachedCachePool(static::$memcachedCient);
}
- static::$endpoint = static::$endpoint ?: $endpoint;
+ static::$endpoint = static::$endpoint ?: $endpoint;
static::$bearerToken = static::$bearerToken ?: $bearerToken;
- static::$bearerPwd = static::$bearerPwd ?: $bearerPwd;
+ static::$bearerPwd = static::$bearerPwd ?: $bearerPwd;
static::$bearerToken = static::$bearerToken ?: Utils::getConfig('crm.token');
- static::$bearerPwd = static::$bearerPwd ?: Utils::getConfig('crm.password');
- static::$endpoint = static::$endpoint ?: Utils::getConfig('crm.endpoint');
+ static::$bearerPwd = static::$bearerPwd ?: Utils::getConfig('crm.password');
+ static::$endpoint = static::$endpoint ?: Utils::getConfig('crm.endpoint');
if (!static::$bearerToken) {
throw new CrmException('Either config or .env file need to have the token var set');
@@ -102,7 +102,7 @@ class ApiInterface
// handle http Auth
if (\strpos(static::$endpoint, '@')) {
- $vars = \parse_url(static::$endpoint);
+ $vars = \parse_url(static::$endpoint);
static::$authentification = \base64_encode($vars['user'] . ':' . $vars['pass']);
}
}
@@ -119,7 +119,7 @@ class ApiInterface
public function call(Request $request, bool $addBearer = false): Response
{
$headers = [];
- $data = [];
+ $data = [];
$this->setHeaders($headers);
$this->setData($data);
$data = array_merge($request->data, $data);
@@ -256,14 +256,14 @@ class ApiInterface
*/
protected function addCredentials(Request $request, bool $addBearer = false)
{
- $params = [];
+ $params = [];
$authentification = [];
if (static::$authentification) {
$authentification[] = sprintf('Basic %s', static::$authentification);
}
if ($addBearer) {
$authentification[] = sprintf('Bearer %s', static::$bearerToken);
- $params['data'] = ['bearer_pwd' => static::$bearerPwd];
+ $params['data'] = ['bearer_pwd' => static::$bearerPwd];
}
if ($authentification) {
$params['headers'] = ['Authorization' => implode(',', $authentification)];
diff --git a/src/Transport/Request.php b/src/Transport/Request.php
index 4145eee..3931958 100644
--- a/src/Transport/Request.php
+++ b/src/Transport/Request.php
@@ -85,7 +85,7 @@ class Request
*
* @var integer
*/
- protected $maxAttemps = 1;
+ protected $maxAttemps = 3;
/**
* Current attempt to login
@@ -100,14 +100,14 @@ class Request
array $headers = [],
array $data = []
) {
- $this->hidden = function () {
+ $this->hidden = function () {
return [];
};
- $this->method = $method;
- $this->uri = $uri;
- $this->data = $data;
+ $this->method = $method;
+ $this->uri = $uri;
+ $this->data = $data;
$this->headers = $headers;
- $this->client = new Client([
+ $this->client = new Client([
RequestOptions::HEADERS => [
'User-Agent' => sprintf(
'LDC CRM Client v%s',
@@ -138,7 +138,7 @@ class Request
$uri = sprintf("%s?%s", $uri, http_build_query($this->data));
}
$headers = array_merge($this->headers, ($this->hidden)('headers'));
- $data = array_merge($this->data, ($this->hidden)('data'));
+ $data = array_merge($this->data, ($this->hidden)('data'));
return new Psr7Request(
\strtoupper($this->method),
sprintf('%s/%s', $this->endpoint, $uri),
@@ -241,7 +241,7 @@ class Request
*/
public function maxAttempted(): bool
{
- return $this->attemps;
+ return $this->attemps >= $this->maxAttemps;
}
/**
diff --git a/src/Transport/Response.php b/src/Transport/Response.php
index ea51c33..9409f64 100644
--- a/src/Transport/Response.php
+++ b/src/Transport/Response.php
@@ -78,9 +78,9 @@ class Response
public function __construct(ApiStatus $status, ResponseInterface $response)
{
$this->response = $response;
- $this->status = $status;
+ $this->status = $status;
$this->httpCode = $response->getStatusCode();
- $this->headers = $response->getHeaders();
+ $this->headers = $response->getHeaders();
/** @var \GuzzleHttp\Psr7\Stream */
$this->body = $response->getBody();
@@ -104,7 +104,7 @@ class Response
$this->apiError = $this->body['data']['code'];
} else {
$this->apiError = ApiError::make($this->body['data']['code']);
- $this->message = $this->body['data']['message'];
+ $this->message = $this->body['data']['message'];
if ($this->apiError->equals(ApiError::validationFailed())) {
$errors = new RecursiveIteratorIterator(
new RecursiveArrayIterator($this->body['data']['errors'])
@@ -150,9 +150,9 @@ class Response
private function checkVersion(string $version)
{
- $packageInfo = Utils::getPackageInfo();
+ $packageInfo = Utils::getPackageInfo();
$ApackageInfo = explode('.', $packageInfo['version']);
- $Aversion = \explode('.', $version);
+ $Aversion = \explode('.', $version);
if ($ApackageInfo[0] != $Aversion[0]) {
throw new CrmException(sprintf(
'Incompatible major versions between CRM server %s and client %s',
diff --git a/src/Utils.php b/src/Utils.php
index 2056ca9..8d36d5a 100644
--- a/src/Utils.php
+++ b/src/Utils.php
@@ -45,6 +45,7 @@ class Utils
private static $translations = [];
/**
+ * TODO: refactorize this
* Create a new Validator instance.
*
* @param array $data
@@ -67,14 +68,14 @@ class Utils
$closureFail = function ($message) {
throw new ValidationException($message);
};
- $closure = null;
- $rParams = [];
+ $closure = null;
+ $rParams = [];
if (\is_callable($rule) and !is_string($rule)) {
$closure = $rule;
- $rule = 'closure';
+ $rule = 'closure';
} elseif (\strpos($rule, ':') !== false) {
$rParams = \explode(':', $rule, 2);
- $rule = \array_shift($rParams);
+ $rule = \array_shift($rParams);
}
switch ($rule) {
case 'required':
@@ -176,7 +177,8 @@ class Utils
return \preg_match('/[a-z]/', $data[$attribute]) and
\preg_match('/[A-Z]/', $data[$attribute]);
},
- 'error' => self::translate($attribute) . ' doit contenir des lettre minuscules et majuscules'
+ 'error' => self::translate($attribute) .
+ ' doit contenir des lettre minuscules et majuscules'
];
break;
case 'containDigit':
@@ -279,7 +281,7 @@ class Utils
try {
if (!self::$config) {
- $dotenv = Dotenv::createImmutable(__DIR__ . '/..');
+ $dotenv = Dotenv::createImmutable(__DIR__ . '/..');
self::$config = $dotenv->load();
}
} catch (\Dotenv\Exception\InvalidPathException $e) {
@@ -307,7 +309,7 @@ class Utils
$query = \array_map(function ($v) {
return is_bool($v) ? (int)$v : $v;
}, $query);
- $data = \array_map(function ($v) {
+ $data = \array_map(function ($v) {
return is_bool($v) ? (int)$v : $v;
}, $data);
@@ -315,8 +317,8 @@ class Utils
if (!isset($routes[$routeName])) {
throw new \Exception("Unknown route $routeName from the crm");
}
- $route = $routes[$routeName];
- $matches = [];
+ $route = $routes[$routeName];
+ $matches = [];
$matchedIndex = [];
\preg_match_all('/{([\w-]*)}/', $route['uri'], $matches);
if (\count($matches[0])) {
@@ -324,7 +326,7 @@ class Utils
if (!isset($query[$matches[1][$k]])) {
throw new \Exception(sprintf('Missing required parameter %s', $matches[1][$k]));
}
- $route['uri'] = str_replace($match, $query[$matches[1][$k]], $route['uri']);
+ $route['uri'] = str_replace($match, $query[$matches[1][$k]], $route['uri']);
$matchedIndex[$matches[1][$k]] = $query[$matches[1][$k]];
}
}
diff --git a/src/WordPress/WPCrm.php b/src/WordPress/WPCrm.php
index 8d709f5..0bee037 100644
--- a/src/WordPress/WPCrm.php
+++ b/src/WordPress/WPCrm.php
@@ -627,7 +627,7 @@ class WPCrm
protected static function getRawProperty(object $object, string $field)
{
$refClass = new ReflectionClass(\get_class($object));
- $refProp = $refClass->getProperty($field);
+ $refProp = $refClass->getProperty($field);
$refProp->setAccessible(true);
return $refProp->getValue($object);
}
diff --git a/src/WordPress/WPCrmAnswer.php b/src/WordPress/WPCrmAnswer.php
index 27da80b..92cb288 100644
--- a/src/WordPress/WPCrmAnswer.php
+++ b/src/WordPress/WPCrmAnswer.php
@@ -61,7 +61,7 @@ abstract class WPCrmAnswer
protected static function getRawProperty(object $object, string $field)
{
$refClass = new ReflectionClass(\get_class($object));
- $refProp = $refClass->getProperty($field);
+ $refProp = $refClass->getProperty($field);
$refProp->setAccessible(true);
return $refProp->getValue($object);
}
diff --git a/src/WordPress/WPCrmQuestion.php b/src/WordPress/WPCrmQuestion.php
index e54b8f5..b9491e0 100644
--- a/src/WordPress/WPCrmQuestion.php
+++ b/src/WordPress/WPCrmQuestion.php
@@ -104,7 +104,7 @@ abstract class WPCrmQuestion
protected static function getRawProperty(object $object, string $field)
{
$refClass = new ReflectionClass(\get_class($object));
- $refProp = $refClass->getProperty($field);
+ $refProp = $refClass->getProperty($field);
$refProp->setAccessible(true);
return $refProp->getValue($object);
}
diff --git a/src/WordPress/WPCrmUser.php b/src/WordPress/WPCrmUser.php
index dd62be8..f621d48 100644
--- a/src/WordPress/WPCrmUser.php
+++ b/src/WordPress/WPCrmUser.php
@@ -166,7 +166,7 @@ class WPCrmUser implements JsonSerializable
*/
public function setInfo(Customer $customer)
{
- $this->info = $customer;
+ $this->info = $customer;
$this->pemail = $customer->email;
$this->phashcode = $customer->hashcode;
}