phpcs pass
This commit is contained in:
parent
a004852c3c
commit
94db0de47b
16 changed files with 66 additions and 63 deletions
|
|
@ -18,13 +18,14 @@
|
|||
<rule ref="Generic.ControlStructures.InlineControlStructure" />
|
||||
<rule ref="Generic.Files.ByteOrderMark" />
|
||||
<rule ref="Generic.Files.LineEndings" />
|
||||
<rule ref="Generic.Formatting.DisallowMultipleStatements" />
|
||||
<rule ref="Generic.Formatting.MultipleStatementAlignment" />
|
||||
<rule ref="Generic.Files.LineLength">
|
||||
<properties>
|
||||
<property name="lineLimit" value="120"/>
|
||||
<property name="absoluteLineLimit" value="0"/>
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="Generic.Formatting.DisallowMultipleStatements" />
|
||||
<rule ref="Generic.Formatting.NoSpaceAfterCast" />
|
||||
<rule ref="Generic.Functions.CallTimePassByReference" />
|
||||
<rule ref="Generic.Functions.FunctionCallArgumentSpacing" />
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = [];
|
||||
|
|
|
|||
|
|
@ -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 = [];
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)];
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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]];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue