fix codestyle

This commit is contained in:
osaajani 2020-06-23 21:06:13 +02:00
parent 350dbb5b59
commit adef27f862
37 changed files with 556 additions and 488 deletions

View file

@ -69,14 +69,14 @@ namespace controllers\internals;
}
/**
* Analyse a message to check if it's a command so execute it
* Analyse a message to check if it's a command so execute it.
*
* @param int $id_user : User id to search a command for
* @param string $message : Message to analyse
*
* @return mixed bool|string : false if not a valid command, anonymized message if valid command
*/
public function analyze_and_process (int $id_user, string $message)
public function analyze_and_process(int $id_user, string $message)
{
if (!ENABLE_COMMAND)
{

View file

@ -39,7 +39,7 @@ namespace controllers\internals;
{
new \daemons\Webhook();
}
/**
* Start mailer daemon.
*/
@ -98,13 +98,12 @@ namespace controllers\internals;
}
/**
* Update a user status.
*
* Update a user status
*
* @param string $email : User email
* @param string $email : User email
* @param string $status : User status, default \models\User::STATUS_ACTIVE
*/
public function update_user_status (string $email, string $status)
public function update_user_status(string $email, string $status)
{
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8');
$internal_user = new \controllers\internals\User($bdd);

View file

@ -148,7 +148,7 @@ namespace controllers\internals;
$i = 0;
foreach ($line as $key => $value)
{
$i++;
++$i;
if ($i < 3)
{
continue;
@ -164,7 +164,7 @@ namespace controllers\internals;
}
$datas = json_encode($datas);
try
try
{
$success = $this->create($id_user, $line[array_keys($line)[1]], $line[array_keys($line)[0]], $datas);
if ($success)

View file

@ -20,20 +20,23 @@ class ExpressionProvider implements ExpressionFunctionProviderInterface
{
//Override default constant() function to make it return null
//This will prevent the use of constant() func to read constants with security impact (such as session, db credentials, etc.)
$neutralized_constant = new ExpressionFunction('constant', function ($str) {
$neutralized_constant = new ExpressionFunction('constant', function ($str)
{
return null;
}, function ($arguments, $str) {
}, function ($arguments, $str)
{
return null;
});
//Exists must be personnalized because it inverse is_null
$exists = new ExpressionFunction('exists', function ($var) {
$exists = new ExpressionFunction('exists', function ($var)
{
return sprintf('!is_null(%1$s)', $str);
}, function ($arguments, $var) {
return !is_null($var);
}, function ($arguments, $var)
{
return null !== $var;
});
return [
$neutralized_constant,
$exists,

View file

@ -27,9 +27,9 @@ namespace controllers\internals;
}
/**
* Return unknown error page
* Return unknown error page.
*/
public function unknown ()
public function unknown()
{
http_response_code(500);
$this->render('error/unknown');

View file

@ -1,35 +1,43 @@
<?php
/*
* This file is part of RaspiSMS.
*
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
*
* This source file is subject to the GPL-3.0 license that is bundled
* with this source code in the file LICENSE.
*/
namespace controllers\internals;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
/**
* Mailing class
* Mailing class.
*/
class Mailer extends \descartes\Controller
{
private $log;
private $mail;
public function __construct ()
public function __construct()
{
$this->log = new Logger('Mailer');
$this->log->pushHandler(new StreamHandler(PWD_LOGS . '/mail.log', Logger::DEBUG));
$this->mail = new PHPMailer(true);
$this->mail->CharSet = 'utf-8';
$this->mail->SMTPDebug = SMTP::DEBUG_OFF;
$this->mail->CharSet = 'utf-8';
$this->mail->SMTPDebug = SMTP::DEBUG_OFF;
$this->mail->isSMTP();
$this->mail->Host = MAIL['SMTP']['HOST'];
$this->mail->SMTPAuth = true;
$this->mail->Username = MAIL['SMTP']['USER'];
$this->mail->Password = MAIL['SMTP']['PASS'];
$this->mail->Port = MAIL['SMTP']['PORT'];
$this->mail->Host = MAIL['SMTP']['HOST'];
$this->mail->SMTPAuth = true;
$this->mail->Username = MAIL['SMTP']['USER'];
$this->mail->Password = MAIL['SMTP']['PASS'];
$this->mail->Port = MAIL['SMTP']['PORT'];
$this->mail->setFrom(MAIL['FROM']);
if (MAIL['SMTP']['TLS'])
@ -39,15 +47,17 @@ class Mailer extends \descartes\Controller
}
/**
* Send email
* @param array $destinations : Destinations address
* @param string $subject : Message subject
* @param string $message : Message
* @param ?string $alt_message : Alt Message if no html support. Null if message is not html.
* @param array $attachments : List of path to attachment files
* Send email.
*
* @param array $destinations : Destinations address
* @param string $subject : Message subject
* @param string $message : Message
* @param ?string $alt_message : Alt Message if no html support. Null if message is not html.
* @param array $attachments : List of path to attachment files
*
* @return bool : false on error, true else
*/
public function send (array $destinations, string $subject, string $message, ?string $alt_message = null, array $attachments = [])
public function send(array $destinations, string $subject, string $message, ?string $alt_message = null, array $attachments = [])
{
try
{
@ -66,7 +76,7 @@ class Mailer extends \descartes\Controller
$mail->Subject = $subject;
$mail->Body = $message;
if ($alt_message)
{
$mail->isHTML($html);
@ -74,32 +84,61 @@ class Mailer extends \descartes\Controller
}
$mail->send();
return true;
}
catch (\Throwable $t)
{
$this->log->error('Error sending mail : ' . $t);
return false;
}
}
/**
* Generate an email body
* @param array $settings : [
* string 'type' => Internal RaspiSMS email type,
* string 'subject' => Email subject,
* string 'template' => Email template to use
* ?string 'alt_template' => Template to use for alt message, if null ignore
* ]
* Enqueue an email for later sending.
*
* @param string $destination : email address to send email to
* @param array $settings : Email settings
* @param array $datas : Datas to inject into email template
*
* @return bool : true on success, false on error
*/
public function enqueue(string $destination, array $settings, array $datas): bool
{
$response = $this->generate_body($settings, $datas);
$message = [
'destinations' => [$destination],
'subject' => $settings['subject'],
'body' => $response['body'],
'alt_body' => $response['alt_body'],
];
$error_code = null;
$queue = msg_get_queue(QUEUE_ID_EMAIL);
$success = msg_send($queue, QUEUE_TYPE_EMAIL, $message, true, true, $error_code);
return (bool) $success;
}
/**
* Generate an email body.
*
* @param array $settings : [
* string 'type' => Internal RaspiSMS email type,
* string 'subject' => Email subject,
* string 'template' => Email template to use
* ?string 'alt_template' => Template to use for alt message, if null ignore
* ]
* @param array : Datas to inject into email template
*
* @return array [
* string 'body' => email body
* ?string 'alt_body' => email alternative body if needed
* ]
* string 'body' => email body
* ?string 'alt_body' => email alternative body if needed
* ]
*/
private function generate_body(array $settings, array $datas) : array
private function generate_body(array $settings, array $datas): array
{
//Generate body of email
ob_start();
@ -114,34 +153,10 @@ class Mailer extends \descartes\Controller
$this->render($settings['alt_template'], $datas);
$alt_body = ob_get_clean();
}
return [
'body' => $body,
'body' => $body,
'alt_body' => $alt_body,
];
}
/**
* Enqueue an email for later sending
* @param string $destination : email address to send email to
* @param array $settings : Email settings
* @param array $datas : Datas to inject into email template
* @return bool : true on success, false on error
*/
public function enqueue (string $destination, array $settings, array $datas) : bool
{
$response = $this->generate_body($settings, $datas);
$message = [
'destinations' => [$destination],
'subject' => $settings['subject'],
'body' => $response['body'],
'alt_body' => $response['alt_body'],
];
$error_code = null;
$queue = msg_get_queue(QUEUE_ID_EMAIL);
$success = msg_send($queue, QUEUE_TYPE_EMAIL, $message, true, true, $error_code);
return (bool) $success;
}
}

View file

@ -28,7 +28,7 @@ namespace controllers\internals;
}
/**
* Return a phone by his name
* Return a phone by his name.
*
* @param string $name : Phone name
*
@ -40,10 +40,10 @@ namespace controllers\internals;
}
/**
* Return a phone for a user by a name
* Return a phone for a user by a name.
*
* @param int $id_user : user id
* @param string $name : Phone name
* @param string $name : Phone name
*
* @return array
*/
@ -56,7 +56,7 @@ namespace controllers\internals;
* Create a phone.
*
* @param int $id_user : User to insert phone for
* @param string $name : The name of the phone
* @param string $name : The name of the phone
* @param string $adapter : The adapter to use the phone
* @param string json $adapter_datas : A JSON string representing adapter's datas (for example credentials for an api)
*
@ -79,7 +79,7 @@ namespace controllers\internals;
*
* @param int $id_user : User to insert phone for
* @param int $id : Phone id
* @param string $name : The name of the phone
* @param string $name : The name of the phone
* @param string $adapter : The adapter to use the phone
* @param array $adapter_datas : An array of the datas of the adapter (for example credentials for an api)
*

View file

@ -36,9 +36,9 @@ namespace controllers\internals;
* @param int $id_phone : Id of the number the message was send with
* @param $at : Reception date
* @param $text : Text of the message
* @param string $origin : Number of the sender
* @param string $status : Status of the received message
* @param bool $command : Is the sms a command
* @param string $origin : Number of the sender
* @param string $status : Status of the received message
* @param bool $command : Is the sms a command
*
* @return mixed : false on error, new received id else
*/
@ -203,31 +203,21 @@ namespace controllers\internals;
}
/**
* Get the model for the Controller.
* Receive a SMS message.
*
* @return \descartes\Model
*/
protected function get_model(): \descartes\Model
{
$this->model = $this->model ?? new \models\Received($this->bdd);
return $this->model;
}
/**
* Receive a SMS message
* @param int $id_user : Id of user to create sended message for
* @param int $id_user : Id of user to create sended message for
* @param int $id_phone : Id of the phone the message was sent to
* @param $text : Text of the message
* @param string $origin : Number of the sender
* @param ?string $at : Message reception date, if null use current date
* @param string $status : Status of a the sms. By default \models\Received::STATUS_UNREAD
* @param string $origin : Number of the sender
* @param ?string $at : Message reception date, if null use current date
* @param string $status : Status of a the sms. By default \models\Received::STATUS_UNREAD
*
* @return array : [
* bool 'error' => false if success, true else
* ?string 'error_message' => null if success, error message else
* ]
* bool 'error' => false if success, true else
* ?string 'error_message' => null if success, error message else
* ]
*/
public function receive (int $id_user, int $id_phone, string $text, string $origin, ?string $at = null, string $status = \models\Received::STATUS_UNREAD) : array
public function receive(int $id_user, int $id_phone, string $text, string $origin, ?string $at = null, string $status = \models\Received::STATUS_UNREAD): array
{
$return = [
'error' => false,
@ -240,8 +230,8 @@ namespace controllers\internals;
//Process the message to check plus potentially execute command and anonymize text
$internal_command = new Command($this->bdd);
$response = $internal_command->analyze_and_process($id_user, $text);
if ($response !== false) //Received sms is a command an we must use anonymized text
{
if (false !== $response)
{ //Received sms is a command an we must use anonymized text
$is_command = true;
$text = $response;
}
@ -251,6 +241,7 @@ namespace controllers\internals;
{
$return['error'] = true;
$return['error_message'] = 'Impossible to insert the sms in database.';
return $return;
}
@ -267,6 +258,19 @@ namespace controllers\internals;
$internal_user = new User($this->bdd);
$internal_user->transfer_received($id_user, $received);
return $return;
}
/**
* Get the model for the Controller.
*
* @return \descartes\Model
*/
protected function get_model(): \descartes\Model
{
$this->model = $this->model ?? new \models\Received($this->bdd);
return $this->model;
}
}

View file

@ -18,7 +18,7 @@ namespace controllers\internals;
/**
* Create a sended.
*
* @param int $id_user : Id of user to create sended message for
* @param int $id_user : Id of user to create sended message for
* @param int $id_phone : Id of the number the message was send with
* @param $at : Reception date
* @param $text : Text of the message
@ -111,7 +111,7 @@ namespace controllers\internals;
/**
* Return sended for an uid and an adapter.
*
* @param int $id_user : user id
* @param int $id_user : user id
* @param string $uid : Uid of the sended
* @param string $adapter : Adapter used to send the message
*
@ -157,32 +157,22 @@ namespace controllers\internals;
}
/**
* Get the model for the Controller.
* Send a SMS message.
*
* @return \descartes\Model
*/
protected function get_model(): \descartes\Model
{
$this->model = $this->model ?? new \models\Sended($this->bdd);
return $this->model;
}
/**
* Send a SMS message
* @param \adapters\AdapterInterface $adapter : Adapter object to use to send the message
* @param int $id_user : Id of user to create sended message for
* @param int $id_phone : Id of the phone the message was send with
* @param \adapters\AdapterInterface $adapter : Adapter object to use to send the message
* @param int $id_user : Id of user to create sended message for
* @param int $id_phone : Id of the phone the message was send with
* @param $text : Text of the message
* @param string $destination : Number of the receiver
* @param bool $flash : Is the sms a flash. By default false.
* @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN
*
* @return array : [
* bool 'error' => false if success, true else
* ?string 'error_message' => null if success, error message else
* ]
* bool 'error' => false if success, true else
* ?string 'error_message' => null if success, error message else
* ]
*/
public function send (\adapters\AdapterInterface $adapter, int $id_user, int $id_phone, string $text, string $destination, bool $flash = false, string $status = \models\Sended::STATUS_UNKNOWN) : array
public function send(\adapters\AdapterInterface $adapter, int $id_user, int $id_phone, string $text, string $destination, bool $flash = false, string $status = \models\Sended::STATUS_UNKNOWN): array
{
$return = [
'error' => false,
@ -198,6 +188,7 @@ namespace controllers\internals;
$return['error_message'] = $response['error_message'];
$status = \models\Sended::STATUS_FAILED;
$this->create($id_user, $id_phone, $at, $text, $destination, $response['uid'] ?? uniqid(), $adapter->meta_classname(), $flash, $status);
return $return;
}
@ -213,7 +204,19 @@ namespace controllers\internals;
$internal_webhook = new Webhook($this->bdd);
$internal_webhook->trigger($id_user, \models\Webhook::TYPE_SEND, $sended);
return $return;
}
/**
* Get the model for the Controller.
*
* @return \descartes\Model
*/
protected function get_model(): \descartes\Model
{
$this->model = $this->model ?? new \models\Sended($this->bdd);
return $this->model;
}
}

View file

@ -17,7 +17,7 @@ namespace controllers\internals;
public function __construct(?\PDO $bdd = null)
{
if ($bdd === null)
if (null === $bdd)
{
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
}

View file

@ -106,12 +106,11 @@ namespace controllers\internals;
{
return (bool) $this->model_user->update_email($id, $email);
}
/**
* Update user status.
*
* @param string $id : user id
* @param string $id : user id
* @param string $status : new status
*
* @return boolean;
@ -181,13 +180,13 @@ namespace controllers\internals;
/**
* Update a user by his id.
*
* @param mixed $id
* @param mixed $email
* @param mixed $password
* @param mixed $admin
* @param mixed $api_key
* @param string $status : User status
* @param bool $encrypt_password : Should the password be encrypted, by default true
* @param mixed $id
* @param mixed $email
* @param mixed $password
* @param mixed $admin
* @param mixed $api_key
* @param string $status : User status
* @param bool $encrypt_password : Should the password be encrypted, by default true
*
* @return int : Number of modified user
*/
@ -210,9 +209,9 @@ namespace controllers\internals;
* @param mixed $email
* @param mixed $password
* @param mixed $admin
* @param ?string $api_key : The api key of the user, if null generate randomly
* @param string $status : User status, default \models\User::STATUS_ACTIVE
* @param bool $encrypt_password : Should the password be encrypted, by default true
* @param ?string $api_key : The api key of the user, if null generate randomly
* @param string $status : User status, default \models\User::STATUS_ACTIVE
* @param bool $encrypt_password : Should the password be encrypted, by default true
*
* @return mixed bool|int : false on error, id of the new user else
*/
@ -255,21 +254,21 @@ namespace controllers\internals;
return bin2hex(random_bytes(16));
}
/**
* Transfer a received sms to user email
* @param int $id_user : User id
* Transfer a received sms to user email.
*
* @param int $id_user : User id
* @param array $received : [
* int 'id' => sms id,
* string 'at' => sms reception date,
* string 'text' => sms content,
* string 'destination' => id of phone the sms was sent to
* string 'origin' => phone number that sent the sms
* ]
* int 'id' => sms id,
* string 'at' => sms reception date,
* string 'text' => sms content,
* string 'destination' => id of phone the sms was sent to
* string 'origin' => phone number that sent the sms
* ]
*
* @return bool : False if no transfer, true else
*/
public function transfer_received (int $id_user, array $received) : bool
public function transfer_received(int $id_user, array $received): bool
{
$settings = $this->internal_setting->gets_for_user($id_user);
@ -291,6 +290,7 @@ namespace controllers\internals;
}
$mailer = new Mailer();
return $mailer->enqueue($user['email'], EMAIL_TRANSFER_SMS, [
'at' => $received['at'],
'origin' => $received['origin'],

View file

@ -87,33 +87,22 @@ class Webhook extends StandardController
return $this->get_model()->gets_for_type_and_user($id_user, $type);
}
/**
* Get the model for the Controller.
*
* @return \descartes\Model
*/
protected function get_model(): \descartes\Model
{
$this->model = $this->model ?? new \models\Webhook($this->bdd);
return $this->model;
}
/**
* Trigger a webhook and transmit the signal to webhook daemon if needed.
* @param int $id_user : User to trigger the webhook for
* @param string $type : Type of webhook to trigger
* @param array $sms : The sms [
* int 'id' => SMS id,
* string 'at' => SMS date,
* string 'text' => sms body,
* string 'origin' => sms origin (number or phone id)
* string 'destination' => sms destination (number or phone id)
* ]
*
* @param int $id_user : User to trigger the webhook for
* @param string $type : Type of webhook to trigger
* @param array $sms : The sms [
* int 'id' => SMS id,
* string 'at' => SMS date,
* string 'text' => sms body,
* string 'origin' => sms origin (number or phone id)
* string 'destination' => sms destination (number or phone id)
* ]
*
* @return bool : False if no trigger, true else
*/
public function trigger (int $id_user, string $type, array $sms)
public function trigger(int $id_user, string $type, array $sms)
{
$internal_setting = new Setting($this->bdd);
$settings = $internal_setting->gets_for_user($id_user);
@ -141,7 +130,20 @@ class Webhook extends StandardController
$error_code = null;
$queue = msg_get_queue(QUEUE_ID_WEBHOOK);
$success = msg_send($queue, QUEUE_TYPE_WEBHOOK, $message, true, true, $error_code);
return (bool) $success;
}
}
/**
* Get the model for the Controller.
*
* @return \descartes\Model
*/
protected function get_model(): \descartes\Model
{
$this->model = $this->model ?? new \models\Webhook($this->bdd);
return $this->model;
}
}

View file

@ -90,8 +90,8 @@ namespace controllers\publics;
exit(self::ERROR_CODES['INVALID_CREDENTIALS']);
}
if ($this->user['status'] !== \models\User::STATUS_ACTIVE)
if (\models\User::STATUS_ACTIVE !== $this->user['status'])
{
$return = self::DEFAULT_RETURN;
$return['error'] = self::ERROR_CODES['SUSPENDED_USER'];
@ -121,6 +121,7 @@ namespace controllers\publics;
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'entry_type must be one of : ' . implode(', ', $entry_types) . '.';
$this->auto_http_code(false);
return $this->json($return);
}
@ -165,6 +166,7 @@ namespace controllers\publics;
}
$this->auto_http_code(true);
return $this->json($return);
}
@ -182,7 +184,7 @@ namespace controllers\publics;
*
* @return : Id of scheduled created
*/
public function post_scheduled ()
public function post_scheduled()
{
$at = $_POST['at'] ?? false;
$text = $_POST['text'] ?? false;
@ -193,10 +195,10 @@ namespace controllers\publics;
$groups = $_POST['groups'] ?? [];
$conditional_groups = $_POST['conditional_groups'] ?? [];
$numbers = is_array($numbers) ? $numbers : [$numbers];
$contacts = is_array($contacts) ? $contacts : [$contacts];
$groups = is_array($groups) ? $groups : [$groups];
$conditional_groups = is_array($conditional_groups) ? $conditional_groups : [$conditional_groups];
$numbers = \is_array($numbers) ? $numbers : [$numbers];
$contacts = \is_array($contacts) ? $contacts : [$contacts];
$groups = \is_array($groups) ? $groups : [$groups];
$conditional_groups = \is_array($conditional_groups) ? $conditional_groups : [$conditional_groups];
if (!$at)
{
@ -209,6 +211,7 @@ namespace controllers\publics;
$return['error'] = self::ERROR_CODES['MISSING_PARAMETER'];
$return['message'] = self::ERROR_MESSAGES['MISSING_PARAMETER'] . ($at ? '' : 'at ') . ($text ? '' : 'text');
$this->auto_http_code(false);
return $this->json($return);
}
@ -218,6 +221,7 @@ namespace controllers\publics;
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'at must be a date of format "Y-m-d H:i:s".';
$this->auto_http_code(false);
return $this->json($return);
}
@ -241,6 +245,7 @@ namespace controllers\publics;
$return['error'] = self::ERROR_CODES['MISSING_PARAMETER'];
$return['message'] = self::ERROR_MESSAGES['MISSING_PARAMETER'] . 'You must specify at least one valid number, contact, group or conditional_group.';
$this->auto_http_code(false);
return $this->json($return);
}
@ -250,6 +255,7 @@ namespace controllers\publics;
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'id_phone : You must specify an id_phone number among thoses of user phones.';
$this->auto_http_code(false);
return $this->json($return);
}
@ -260,12 +266,14 @@ namespace controllers\publics;
$return['error'] = self::ERROR_CODES['CANNOT_CREATE'];
$return['message'] = self::ERROR_MESSAGES['CANNOT_CREATE'];
$this->auto_http_code(false);
return $this->json($return);
}
$return = self::DEFAULT_RETURN;
$return['response'] = $scheduled_id;
$this->auto_http_code(true);
return $this->json($return);
}
@ -292,6 +300,7 @@ namespace controllers\publics;
$return['response'] = true;
$this->auto_http_code(true);
return $this->json($return);
}
}

View file

@ -114,9 +114,10 @@ use Monolog\Logger;
}
//Do not update if current status is delivered or failed
if ($sended['status'] === \models\Sended::STATUS_DELIVERED || $sended['status'] === \models\Sended::STATUS_FAILED)
if (\models\Sended::STATUS_DELIVERED === $sended['status'] || \models\Sended::STATUS_FAILED === $sended['status'])
{
$this->logger->info('Callback status update message ignore because status is already ' . $sended['status'] . '.');
return false;
}
@ -125,18 +126,17 @@ use Monolog\Logger;
return true;
}
/**
* Function call on sms reception notification
* We return nothing, and we let the adapter do his things.
*
* @param string $adapter_uid : Uid of the adapter to use
* @param int $id_phone : Phone id
* @param int $id_phone : Phone id
*
* @return bool : true on success, false on error
*/
public function reception (string $adapter_uid, int $id_phone)
public function reception(string $adapter_uid, int $id_phone)
{
$this->logger->info('Callback reception call with adapter uid : ' . $adapter_uid);
@ -171,6 +171,7 @@ use Monolog\Logger;
if ($response['error'])
{
$this->logger->error('Callback reception with adapter ' . $adapter_uid . ' failed : ' . $response['error_message']);
return false;
}
@ -180,10 +181,12 @@ use Monolog\Logger;
if ($response['error'])
{
$this->logger->error('Failed receive message : ' . json_encode($sms) . ' with error : ' . $response['error_message']);
return false;
}
$this->logger->info('Callback reception successfully received message : ' . json_encode($sms));
return true;
}
}

View file

@ -64,7 +64,7 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Connect', 'login'));
}
if ($user['status'] !== \models\User::STATUS_ACTIVE)
if (\models\User::STATUS_ACTIVE !== $user['status'])
{
\FlashMessage\FlashMessage::push('danger', 'Votre compte est actuellement suspendu.');
@ -119,7 +119,7 @@ namespace controllers\publics;
$token = $Tokenista->generate(3600, ['id_user' => $user['id']]);
$reset_link = \descartes\Router::url('Connect', 'reset_password', ['id_user' => $user['id'], 'token' => $token]);
$mailer = new \controllers\internals\Mailer();
$email_send = $mailer->enqueue($email, EMAIL_RESET_PASSWORD, ['reset_link' => $reset_link]);

View file

@ -303,7 +303,7 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Contact', 'list'));
}
$msg = ($result == 1 ? '1' : 'Pas de') . ' nouveau contact inséré.';
$msg = (1 === $result ? '1' : 'Pas de') . ' nouveau contact inséré.';
if ($result > 1)
{
$msg = $result . ' nouveaux contacts ont été insérés.';

View file

@ -52,6 +52,7 @@ class Phone extends \descartes\Controller
if (!$adapter)
{
$phone['adapter'] = 'Inconnu';
continue;
}
@ -111,7 +112,7 @@ class Phone extends \descartes\Controller
* Create a new phone.
*
* @param $csrf : CSRF token
* @param string $_POST['name'] : Phone name
* @param string $_POST['name'] : Phone name
* @param string $_POST['adapter'] : Phone adapter
* @param array $_POST['adapter_datas'] : Phone adapter datas
*/

View file

@ -50,7 +50,7 @@ namespace controllers\publics;
$this->internal_received->mark_as_read_for_user($_SESSION['user']['id'], $received['id']);
}
if ($received['id_phone'] !== null)
if (null !== $received['id_phone'])
{
$phone = $this->internal_phone->get_for_user($_SESSION['user']['id'], $received['id_phone']);
if ($phone)
@ -80,7 +80,7 @@ namespace controllers\publics;
{
$this->internal_received->mark_as_read_for_user($_SESSION['user']['id'], $received['id']);
if ($received['id_phone'] !== null)
if (null !== $received['id_phone'])
{
$phone = $this->internal_phone->get_for_user($_SESSION['user']['id'], $received['id_phone']);
if ($phone)

View file

@ -46,7 +46,7 @@ namespace controllers\publics;
foreach ($sendeds as $key => $sended)
{
if ($sended['id_phone'] !== null)
if (null !== $sended['id_phone'])
{
$phone = $this->internal_phone->get_for_user($_SESSION['user']['id'], $sended['id_phone']);
if ($phone)

View file

@ -45,18 +45,17 @@ class User extends \descartes\Controller
$users = $this->internal_user->list();
$this->render('user/list', ['users' => $users]);
}
/**
* Update status of users
* Update status of users.
*
* @param array int $_GET['ids'] : User ids
* @param mixed $csrf
* @param int $status : 1 -> active, 0 -> suspended
* @param int $status : 1 -> active, 0 -> suspended
*
* @return boolean;
*/
public function update_status ($csrf, int $status)
public function update_status($csrf, int $status)
{
if (!$this->verify_csrf($csrf))
{
@ -65,7 +64,7 @@ class User extends \descartes\Controller
return $this->redirect(\descartes\Router::url('User', 'list'));
}
if ($status == 0)
if (0 === $status)
{
$status = \models\User::STATUS_SUSPENDED;
}
@ -83,7 +82,6 @@ class User extends \descartes\Controller
return $this->redirect(\descartes\Router::url('User', 'list'));
}
/**
* Cette fonction va supprimer une liste de users.
*