style validation fix

This commit is contained in:
osaajani 2021-06-17 00:51:33 +02:00
parent f1d47a25ed
commit 017c7fee53
42 changed files with 526 additions and 497 deletions

View File

@ -84,22 +84,22 @@ interface AdapterInterface
public static function meta_support_status_change(): bool;
/**
* Does the implemented service support mms reception
* Does the implemented service support mms reception.
*/
public static function meta_support_mms_reception(): bool;
/**
* Does the implemented service support mms sending
* Does the implemented service support mms sending.
*/
public static function meta_support_mms_sending(): bool;
/**
* Does the implemented service support inbound call callback
* Does the implemented service support inbound call callback.
*/
public static function meta_support_inbound_call_callback(): bool;
/**
* Does the implemented service support end call callback
* Does the implemented service support end call callback.
*/
public static function meta_support_end_call_callback(): bool;
@ -118,7 +118,7 @@ interface AdapterInterface
* array 'uid' => Uid of the sms created on success
* ]
*/
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array;
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array;
/**
* Method called to read SMSs of the number.
@ -174,7 +174,7 @@ interface AdapterInterface
public static function reception_callback(): array;
/**
* Method called on reception of an inbound_call notification
* Method called on reception of an inbound_call notification.
*
* @return array : [
* bool 'error' => false on success, true on error
@ -189,9 +189,8 @@ interface AdapterInterface
*/
public function inbound_call_callback(): array;
/**
* Method called on reception of a end call notification
* Method called on reception of a end call notification.
*
* @return array : [
* bool 'error' => false on success, true on error

View File

@ -127,7 +127,7 @@ namespace adapters;
}
/**
* Does the implemented service support mms reception
* Does the implemented service support mms reception.
*/
public static function meta_support_mms_reception(): bool
{
@ -135,7 +135,7 @@ namespace adapters;
}
/**
* Does the implemented service support mms sending
* Does the implemented service support mms sending.
*/
public static function meta_support_mms_sending(): bool
{
@ -152,7 +152,7 @@ namespace adapters;
return false;
}
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array
{
$response = [
'error' => false,

View File

@ -137,7 +137,7 @@ namespace adapters;
}
/**
* Does the implemented service support mms reception
* Does the implemented service support mms reception.
*/
public static function meta_support_mms_reception(): bool
{
@ -145,7 +145,7 @@ namespace adapters;
}
/**
* Does the implemented service support mms sending
* Does the implemented service support mms sending.
*/
public static function meta_support_mms_sending(): bool
{
@ -162,7 +162,7 @@ namespace adapters;
return false;
}
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array
{
$response = [
'error' => false,

View File

@ -174,7 +174,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
}
/**
* Does the implemented service support mms reception
* Does the implemented service support mms reception.
*/
public static function meta_support_mms_reception(): bool
{
@ -182,7 +182,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
}
/**
* Does the implemented service support mms sending
* Does the implemented service support mms sending.
*/
public static function meta_support_mms_sending(): bool
{
@ -199,7 +199,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
return false;
}
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array
{
$response = [
'error' => false,

View File

@ -179,7 +179,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
}
/**
* Does the implemented service support mms reception
* Does the implemented service support mms reception.
*/
public static function meta_support_mms_reception(): bool
{
@ -187,7 +187,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
}
/**
* Does the implemented service support mms sending
* Does the implemented service support mms sending.
*/
public static function meta_support_mms_sending(): bool
{
@ -204,7 +204,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
return false;
}
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array
{
$response = [
'error' => false,

View File

@ -171,7 +171,7 @@ namespace adapters;
}
/**
* Does the implemented service support mms reception
* Does the implemented service support mms reception.
*/
public static function meta_support_mms_reception(): bool
{
@ -179,7 +179,7 @@ namespace adapters;
}
/**
* Does the implemented service support mms sending
* Does the implemented service support mms sending.
*/
public static function meta_support_mms_sending(): bool
{
@ -196,7 +196,7 @@ namespace adapters;
return false;
}
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array
{
$response = [
'error' => false,

View File

@ -182,7 +182,7 @@ namespace adapters;
}
/**
* Does the implemented service support mms reception
* Does the implemented service support mms reception.
*/
public static function meta_support_mms_reception(): bool
{
@ -190,7 +190,7 @@ namespace adapters;
}
/**
* Does the implemented service support mms sending
* Does the implemented service support mms sending.
*/
public static function meta_support_mms_sending(): bool
{
@ -207,7 +207,7 @@ namespace adapters;
return false;
}
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array
{
$response = [
'error' => false,

View File

@ -132,7 +132,7 @@ namespace adapters;
}
/**
* Does the implemented service support mms reception
* Does the implemented service support mms reception.
*/
public static function meta_support_mms_reception(): bool
{
@ -140,7 +140,7 @@ namespace adapters;
}
/**
* Does the implemented service support mms sending
* Does the implemented service support mms sending.
*/
public static function meta_support_mms_sending(): bool
{
@ -157,7 +157,7 @@ namespace adapters;
return true;
}
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array
{
$response = [
'error' => false,
@ -194,7 +194,7 @@ namespace adapters;
* "mms" : true,
* "origin" : "+33612345678",
* "text" : "SMS Text"
* }
* }.
*/
public function read(): array
{

View File

@ -176,7 +176,7 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
}
/**
* Does the implemented service support mms reception
* Does the implemented service support mms reception.
*/
public static function meta_support_mms_reception(): bool
{
@ -184,7 +184,7 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
}
/**
* Does the implemented service support mms sending
* Does the implemented service support mms sending.
*/
public static function meta_support_mms_sending(): bool
{
@ -201,7 +201,7 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
return false;
}
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array
{
$response = [
'error' => false,

View File

@ -118,7 +118,7 @@ namespace controllers\internals;
}
/**
* List all adapters for a meta value
* List all adapters for a meta value.
*
* @param $search_name : Name of the meta
* @param $search_value : Value of the meta
@ -128,7 +128,9 @@ namespace controllers\internals;
public function list_adapters_with_meta_equal($search_name, $search_value)
{
$adapters = $this->list_adapters();
return array_filter($adapters, function($metas) use ($search_name, $search_value) {
return array_filter($adapters, function ($metas) use ($search_name, $search_value)
{
$match = false;
foreach ($metas as $name => $value)
{

View File

@ -49,15 +49,23 @@ namespace controllers\internals;
switch ($direction)
{
case \models\Call::DIRECTION_OUTBOUND :
if (null === $destination) { return false; }
case \models\Call::DIRECTION_OUTBOUND:
if (null === $destination)
{
return false;
}
break;
case \models\Call::DIRECTION_INBOUND :
if (null === $origin) { return false; }
case \models\Call::DIRECTION_INBOUND:
if (null === $origin)
{
return false;
}
break;
default :
default:
return false;
}
@ -90,9 +98,8 @@ namespace controllers\internals;
return $new_call_id;
}
/**
* End a call
* End a call.
*
* @param int $id_user : Id of the user to end call for
* @param int $id_phone : If of the phone to end call for

View File

@ -109,7 +109,6 @@ namespace controllers\internals;
'admin' => $admin,
'api_key' => $api_key,
'status' => $status,
];
$success = $internal_user->update($user['id'], $user);
@ -161,9 +160,8 @@ namespace controllers\internals;
exit($success ? 0 : 1);
}
/**
* Delete medias that are no longer usefull
* Delete medias that are no longer usefull.
*/
public function clean_unused_medias()
{
@ -176,12 +174,12 @@ namespace controllers\internals;
{
$success = $internal_media->delete_for_user($media['id_user'], $media['id']);
echo ($success === false ? '[KO]' : '[OK]') . ' - ' . $media['path'] . "\n";
echo (false === $success ? '[KO]' : '[OK]') . ' - ' . $media['path'] . "\n";
}
}
/**
* Do alerting for quota limits
* Do alerting for quota limits.
*/
public function quota_limit_alerting()
{
@ -191,7 +189,7 @@ namespace controllers\internals;
}
/**
* Do quota renewal
* Do quota renewal.
*/
public function renew_quotas()
{

View File

@ -57,7 +57,7 @@ namespace controllers\internals;
}
/**
* Gets events for a type, since a date and eventually until a date (both included)
* Gets events for a type, since a date and eventually until a date (both included).
*
* @param int $id_user : User id
* @param string $type : Event type we want
@ -66,9 +66,9 @@ namespace controllers\internals;
*
* @return array
*/
public function get_events_by_type_and_date_for_user (int $id_user, string $type, \DateTime $since, ?\DateTime $until = null)
public function get_events_by_type_and_date_for_user(int $id_user, string $type, \DateTime $since, ?\DateTime $until = null)
{
$this->get_model()->get_events_by_type_and_date_for_user ($id_user, $type, $since, $until);
$this->get_model()->get_events_by_type_and_date_for_user($id_user, $type, $since, $until);
}
/**

View File

@ -39,7 +39,7 @@ class Media extends StandardController
throw new \Exception('File ' . $tmpfile_path . ' is not readable.');
}
$mimey = new \Mimey\MimeTypes;
$mimey = new \Mimey\MimeTypes();
$extension = $extension ?? $mimey->getExtension(mime_content_type($tmpfile_path));
$new_file_name = \controllers\internals\Tool::random_uuid() . '.' . $extension;
@ -86,16 +86,17 @@ class Media extends StandardController
}
/**
* Upload and create a media
* Upload and create a media.
*
* @param int $id_user : Id of the user
* @param array $file : array representing uploaded file, extracted from $_FILES['yourfile']
*
* @return int : Raise exception on error or return new media id on success
*/
public function create_from_uploaded_file_for_user(int $id_user, array $file)
{
$upload_result = \controllers\internals\Tool::read_uploaded_file($file);
if ($upload_result['success'] !== true)
if (true !== $upload_result['success'])
{
throw new \Exception($upload_result['content']);
}
@ -115,7 +116,8 @@ class Media extends StandardController
}
/**
* Link a media to a scheduled, a received or a sended message
* Link a media to a scheduled, a received or a sended message.
*
* @param int $id_media : Id of the media
* @param string $resource_type : Type of resource to link the media to ('scheduled', 'received' or 'sended')
* @param int $resource_id : Id of the resource to link the media to
@ -128,14 +130,17 @@ class Media extends StandardController
{
case 'scheduled':
return $this->get_model()->insert_media_scheduled($id_media, $resource_id);
break;
case 'received':
return $this->get_model()->insert_media_received($id_media, $resource_id);
break;
case 'sended':
return $this->get_model()->insert_media_sended($id_media, $resource_id);
break;
default:
@ -143,9 +148,9 @@ class Media extends StandardController
}
}
/**
* Unlink a media of a scheduled, a received or a sended message
* Unlink a media of a scheduled, a received or a sended message.
*
* @param int $id_media : Id of the media
* @param string $resource_type : Type of resource to unlink the media of ('scheduled', 'received' or 'sended')
* @param int $resource_id : Id of the resource to unlink the media of
@ -158,14 +163,17 @@ class Media extends StandardController
{
case 'scheduled':
return $this->get_model()->delete_media_scheduled($id_media, $resource_id);
break;
case 'received':
return $this->get_model()->delete_media_received($id_media, $resource_id);
break;
case 'sended':
return $this->get_model()->delete_media_sended($id_media, $resource_id);
break;
default:
@ -174,7 +182,8 @@ class Media extends StandardController
}
/**
* Unlink all medias of a scheduled, a received or a sended message
* Unlink all medias of a scheduled, a received or a sended message.
*
* @param string $resource_type : Type of resource to unlink the media of ('scheduled', 'received' or 'sended')
* @param int $resource_id : Id of the resource to unlink the media of
*
@ -186,14 +195,17 @@ class Media extends StandardController
{
case 'scheduled':
return $this->get_model()->delete_all_for_scheduled($resource_id);
break;
case 'received':
return $this->get_model()->delete_all_for_received($resource_id);
break;
case 'sended':
return $this->get_model()->delete_all_for_sended($resource_id);
break;
default:
@ -289,7 +301,8 @@ class Media extends StandardController
}
/**
* Find medias that are not used
* Find medias that are not used.
*
* @return array
*/
public function gets_unused()

View File

@ -44,13 +44,14 @@ namespace controllers\internals;
}
/**
* Check if a phone support mms
* Check if a phone support mms.
*
* @param int $id : id of the phone to check
* @param $type : type of sms support, a const from Phone, MMS_SENDING, MMS_RECEPTION or MMS_BOTH
*
* @return bool : true if support, false else
*/
public function support_mms (int $id, string $type)
public function support_mms(int $id, string $type)
{
$phone = $this->get_model()->get($id);
if (!$phone)
@ -60,16 +61,19 @@ namespace controllers\internals;
switch ($type)
{
case self::MMS_SENDING :
case self::MMS_SENDING:
return $phone['adapter']::meta_support_mms_sending();
break;
case self::MMS_RECEPTION :
case self::MMS_RECEPTION:
return $phone['adapter']::meta_support_mms_reception();
break;
case self::MMS_BOTH :
case self::MMS_BOTH:
return $phone['adapter']::meta_support_mms_sending() && $phone['adapter']::meta_support_mms_reception();
break;
default:
@ -78,13 +82,14 @@ namespace controllers\internals;
}
/**
* Get all phones supporting mms for a user
* Get all phones supporting mms for a user.
*
* @param int $id_user : id of the user
* @param $type : type of sms support, a const from Phone, MMS_SENDING, MMS_RECEPTION or MMS_BOTH
*
* @return array : array of phones supporting mms
*/
public function gets_phone_supporting_mms_for_user (int $id_user, string $type)
public function gets_phone_supporting_mms_for_user(int $id_user, string $type)
{
$phones = $this->get_model()->gets_for_user($id_user);

View File

@ -50,7 +50,6 @@ class Quota extends StandardController
/**
* Update a quota.
*
*
* @param int $id_user : User id
* @param int $id_quota : Quota to update id
* @param array $quota : Fields to update whith new values
@ -63,24 +62,29 @@ class Quota extends StandardController
}
/**
* Check if we have enough credit
* Check if we have enough credit.
*
* @param int $id_user : User id
* @param int $needed : Number of credits we need
*
* @return bool : true if we have enough credit, false else
*/
public function has_enough_credit(int $id_user, int $needed)
{
$remaining_credit = $this->get_model()->get_remaining_credit($id_user, new \DateTime());
return $remaining_credit >= $needed;
}
/**
* Consume some credit
* Consume some credit.
*
* @param int $id_user : User id
* @param int $quantity : Number of credits to consume
*
* @return bool : True on success, false else
*/
public function consume_credit (int $id_user, int $quantity)
public function consume_credit(int $id_user, int $quantity)
{
$result = $this->get_model()->consume_credit($id_user, $quantity);
@ -92,62 +96,65 @@ class Quota extends StandardController
}
/**
* Get quota usage percentage
* Get quota usage percentage.
*
* @param int $id_user : User id
*
* @return float : percentage of quota used
*/
public function get_usage_percentage (int $id_user)
public function get_usage_percentage(int $id_user)
{
return $this->get_model()->get_usage_percentage($id_user, new \DateTime());
}
/**
* Compute how many credit a message represent
* this function count 160 chars per SMS if it can be send as GSM 03.38 encoding and 70 chars per SMS if it can only be send as UTF8
* this function count 160 chars per SMS if it can be send as GSM 03.38 encoding and 70 chars per SMS if it can only be send as UTF8.
*
* @param string $text : Message to send
*
* @return int : Number of credit to send this message
*/
public static function compute_credits_for_message ($text)
public static function compute_credits_for_message($text)
{
//Gsm 03.38 charset to detect if message is compatible or must use utf8
$gsm0338 = array(
'@','Δ',' ','0','¡','P','¿','p',
'£','_','!','1','A','Q','a','q',
'$','Φ','"','2','B','R','b','r',
'¥','Γ','#','3','C','S','c','s',
'è','Λ','¤','4','D','T','d','t',
'é','Ω','%','5','E','U','e','u',
'ù','Π','&','6','F','V','f','v',
'ì','Ψ','\'','7','G','W','g','w',
'ò','Σ','(','8','H','X','h','x',
'Ç','Θ',')','9','I','Y','i','y',
"\n",'Ξ','*',':','J','Z','j','z',
'Ø',"\x1B",'+',';','K','Ä','k','ä',
'ø','Æ',',','<','L','Ö','l','ö',
"\r",'æ','-','=','M','Ñ','m','ñ',
'Å','ß','.','>','N','Ü','n','ü',
'å','É','/','?','O','§','o','à'
);
$gsm0338 = [
'@', 'Δ', ' ', '0', '¡', 'P', '¿', 'p',
'£', '_', '!', '1', 'A', 'Q', 'a', 'q',
'$', 'Φ', '"', '2', 'B', 'R', 'b', 'r',
'¥', 'Γ', '#', '3', 'C', 'S', 'c', 's',
'è', 'Λ', '¤', '4', 'D', 'T', 'd', 't',
'é', 'Ω', '%', '5', 'E', 'U', 'e', 'u',
'ù', 'Π', '&', '6', 'F', 'V', 'f', 'v',
'ì', 'Ψ', '\'', '7', 'G', 'W', 'g', 'w',
'ò', 'Σ', '(', '8', 'H', 'X', 'h', 'x',
'Ç', 'Θ', ')', '9', 'I', 'Y', 'i', 'y',
"\n", 'Ξ', '*', ':', 'J', 'Z', 'j', 'z',
'Ø', "\x1B", '+', ';', 'K', 'Ä', 'k', 'ä',
'ø', 'Æ', ',', '<', 'L', 'Ö', 'l', 'ö',
"\r", 'æ', '-', '=', 'M', 'Ñ', 'm', 'ñ',
'Å', 'ß', '.', '>', 'N', 'Ü', 'n', 'ü',
'å', 'É', '/', '?', 'O', '§', 'o', 'à',
];
$is_gsm0338 = true;
$len = mb_strlen($text);
for ($i = 0; $i < $len; $i++)
for ($i = 0; $i < $len; ++$i)
{
if (!in_array(mb_substr($text, $i, 1), $gsm0338))
{
$is_gsm0338 = false;
break;
}
}
return ($is_gsm0338 ? ceil($len / 160) : ceil($len / 70));
return $is_gsm0338 ? ceil($len / 160) : ceil($len / 70);
}
/**
* Do email alerting for quotas limit close and quotas limit reached
* Do email alerting for quotas limit close and quotas limit reached.
*/
public function alerting_for_limit_close_and_reached()
{
@ -173,11 +180,12 @@ class Quota extends StandardController
if (!$success)
{
echo "Cannot enqueue alert for quota limit close for quota : " . $quota['id'] . "\n";
echo 'Cannot enqueue alert for quota limit close for quota : ' . $quota['id'] . "\n";
continue;
}
echo "Enqueue alert for quota limit close for quota : " . $quota['id'] . "\n";
echo 'Enqueue alert for quota limit close for quota : ' . $quota['id'] . "\n";
$internal_event->create($quota['id_user'], 'QUOTA_LIMIT_CLOSE', round($quota_percentage * 100, 2) . '% of SMS quota limit reached.');
}
@ -197,19 +205,20 @@ class Quota extends StandardController
if (!$success)
{
echo "Cannot enqueue alert for quota limit reached for quota : " . $quota['id'] . "\n";
echo 'Cannot enqueue alert for quota limit reached for quota : ' . $quota['id'] . "\n";
continue;
}
echo "Enqueue alert for quota limit reached for quota : " . $quota['id'] . "\n";
echo 'Enqueue alert for quota limit reached for quota : ' . $quota['id'] . "\n";
$internal_event->create($quota['id_user'], 'QUOTA_LIMIT_REACHED', 'Reached SMS quota limit.');
}
}
/**
* Do quota renewing
* Do quota renewing.
*/
public function renew_quotas ()
public function renew_quotas()
{
$internal_user = new User($this->bdd);
$internal_event = new Event($this->bdd);
@ -254,11 +263,12 @@ class Quota extends StandardController
if (!$success)
{
echo "Cannot update quota : " . $quota['id'] . "\n";
echo 'Cannot update quota : ' . $quota['id'] . "\n";
continue;
}
echo "Update quota : " . $quota['id'] . "\n";
echo 'Update quota : ' . $quota['id'] . "\n";
$internal_event->create($quota['id_user'], 'QUOTA_RENEWAL', 'Renew quota and report ' . $report . ' credits.');
}
}

View File

@ -64,6 +64,7 @@ namespace controllers\internals;
if (!$id_received)
{
$this->bdd->rollBack();
return false;
}
@ -75,6 +76,7 @@ namespace controllers\internals;
if (!$id_media_received)
{
$this->bdd->rollBack();
return false;
}
}
@ -167,6 +169,7 @@ namespace controllers\internals;
* @param int $id_user : User id
* @param string $since : Date we want messages since format Y-m-d H:i:s
* @param string $origin : Number who sent the message
*
* @return array
*/
public function gets_since_date_by_origin_and_user(int $id_user, string $since, string $origin)
@ -301,6 +304,7 @@ namespace controllers\internals;
catch (\Throwable $t)
{
$return['error_message'] = $t->getMessage();
continue; //Better loose the media than the message
}
}

View File

@ -43,7 +43,7 @@ namespace controllers\internals;
'mms' => $mms,
];
if ($text === '')
if ('' === $text)
{
return false;
}
@ -66,6 +66,7 @@ namespace controllers\internals;
if (!$id_scheduled)
{
$this->bdd->rollBack();
return false;
}
@ -76,11 +77,11 @@ namespace controllers\internals;
if (!$id_media_scheduled)
{
$this->bdd->rollBack();
return false;
}
}
foreach ($numbers as $number)
{
$this->get_model()->insert_scheduled_number($id_scheduled, $number);
@ -193,6 +194,7 @@ namespace controllers\internals;
if (!$id_media_scheduled)
{
$this->bdd->rollBack();
return false;
}
}

View File

@ -27,7 +27,7 @@ namespace controllers\internals;
* @param string $adapter : Name of the adapter service used to send the message
* @param bool $flash : Is the sms a flash
* @param bool $mms : Is the sms a MMS. By default false.
* @param array $medias : Array of medias to link to the MMS.
* @param array $medias : Array of medias to link to the MMS
* @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN
*
* @return mixed : false on error, new sended id else
@ -54,6 +54,7 @@ namespace controllers\internals;
if (!$id_sended)
{
$this->bdd->rollback();
return false;
}
@ -139,6 +140,7 @@ namespace controllers\internals;
* @param int $id_user : User id
* @param string $since : Date we want messages since format Y-m-d H:i:s
* @param string $origin : Number who sent the message
*
* @return array
*/
public function gets_since_date_by_destination_and_user(int $id_user, string $since, string $origin)
@ -204,7 +206,7 @@ namespace controllers\internals;
* @param string $destination : Number of the receiver
* @param bool $flash : Is the sms a flash. By default false.
* @param bool $mms : Is the sms a MMS. By default false.
* @param array $medias : Array of medias to link to the MMS.
* @param array $medias : Array of medias to link to the MMS
* @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN
*
* @return array : [
@ -230,7 +232,6 @@ namespace controllers\internals;
return $return;
}
$at = (new \DateTime())->format('Y-m-d H:i:s');
$media_uris = [];
foreach ($medias as $media)

View File

@ -320,26 +320,27 @@ namespace controllers\internals;
}
/**
* Generate a highly random uuid based on timestamp and strong cryptographic random
* Generate a highly random uuid based on timestamp and strong cryptographic random.
*
* @return string
*/
public static function random_uuid()
{
$bytes = random_bytes(16);
return time() . '-' . bin2hex($bytes);
}
/**
* Create a user data public path
* Create a user data public path.
*
* @param int $id_user : The user id
*
* @return string : The created path
*
* @exception Raise exception on error
*/
public static function create_user_public_path (int $id_user)
public static function create_user_public_path(int $id_user)
{
$new_dir = PWD_DATA_PUBLIC . '/' . $id_user;
if (file_exists($new_dir))
@ -354,18 +355,18 @@ namespace controllers\internals;
}
//We do chmod in two times because else umask fuck mkdir permissions
if (!chmod($new_dir, fileperms(PWD_DATA_PUBLIC) & 0777)) //Fileperms return garbage in addition to perms. Perms are only in weak bytes. We must use an octet notation with 0
{
if (!chmod($new_dir, fileperms(PWD_DATA_PUBLIC) & 0777))
{ //Fileperms return garbage in addition to perms. Perms are only in weak bytes. We must use an octet notation with 0
throw new \Exception('Cannot give dir ' . $new_dir . ' rights : ' . decoct(fileperms(PWD_DATA_PUBLIC) & 0777)); //Show error in dec
}
if (posix_getuid() === 0 && !chown($new_dir, fileowner(PWD_DATA_PUBLIC))) //If we are root, try to give the file to a proper user
{
if (0 === posix_getuid() && !chown($new_dir, fileowner(PWD_DATA_PUBLIC)))
{ //If we are root, try to give the file to a proper user
throw new \Exception('Cannot give dir ' . $new_dir . ' to user : ' . fileowner(PWD_DATA_PUBLIC));
}
if (posix_getuid() === 0 && !chgrp($new_dir, filegroup(PWD_DATA_PUBLIC))) //If we are root, try to give the file to a proper group
{
if (0 === posix_getuid() && !chgrp($new_dir, filegroup(PWD_DATA_PUBLIC)))
{ //If we are root, try to give the file to a proper group
throw new \Exception('Cannot give dir ' . $new_dir . ' to group : ' . filegroup(PWD_DATA_PUBLIC));
}

View File

@ -32,7 +32,7 @@ namespace controllers\internals;
}
/**
* Return a list of users by their ids
* Return a list of users by their ids.
*
* @param array $ids : ids of entries to find
*
@ -209,12 +209,13 @@ namespace controllers\internals;
$this->model_user->update($id, $user);
if ($current_quota && $quota === false)
if ($current_quota && false === $quota)
{
$success = $internal_quota->delete_for_user($id, $current_quota['id']);
if (!$success)
{
$this->bdd->rollback();
return false;
}
}
@ -237,7 +238,6 @@ namespace controllers\internals;
}
}
if (!$this->bdd->commit())
{
return false;
@ -277,7 +277,6 @@ namespace controllers\internals;
return false;
}
$success = $this->internal_setting->create_defaults_for_user($new_id_user);
if (!$success)
{
@ -286,8 +285,7 @@ namespace controllers\internals;
return false;
}
if ($quota !== null)
if (null !== $quota)
{
$internal_quota = new Quota($this->bdd);
$success = $internal_quota->create($new_id_user, $quota['credit'], $quota['additional'], $quota['report_unused'], $quota['report_unused_additional'], $quota['auto_renew'], $quota['renew_interval'], $quota['start_date'], $quota['expiration_date']);
@ -299,7 +297,6 @@ namespace controllers\internals;
}
}
if (!$this->bdd->commit())
{
return false;

View File

@ -231,16 +231,16 @@ namespace controllers\publics;
//Iterate over files to re-create individual $_FILES array
$files_arrays = [];
if ($files === false)
if (false === $files)
{
$files_arrays = [];
}
elseif (!is_array($files['name'])) //Only one file uploaded
{
elseif (!is_array($files['name']))
{ //Only one file uploaded
$files_arrays[] = $files;
}
else //multiple files
{
else
{ //multiple files
foreach ($files as $property_name => $files_values)
{
foreach ($files_values as $file_key => $property_value)

View File

@ -34,7 +34,7 @@ namespace controllers\publics;
}
/**
* Page for showing calls list
* Page for showing calls list.
*/
public function list()
{
@ -51,12 +51,14 @@ namespace controllers\publics;
{
switch ($entity['direction'])
{
case \models\Call::DIRECTION_INBOUND :
case \models\Call::DIRECTION_INBOUND:
$entity['origin_formatted'] = \controllers\internals\Tool::phone_link($entity['origin']);
break;
case \models\Call::DIRECTION_OUTBOUND :
case \models\Call::DIRECTION_OUTBOUND:
$entity['destination_formatted'] = \controllers\internals\Tool::phone_link($entity['destination']);
break;
}
}
@ -66,7 +68,7 @@ namespace controllers\publics;
}
/**
* Delete a list of calls
* Delete a list of calls.
*
* @param array int $_GET['ids'] : Ids of calls to delete
* @param string $csrf : csrf token

View File

@ -207,7 +207,6 @@ use Monolog\Logger;
return true;
}
/**
* Function call on call reception notification
* We return nothing, and we let the adapter do his things.
@ -273,7 +272,6 @@ use Monolog\Logger;
return true;
}
/**
* Function call on end call notification
* We return nothing, and we let the adapter do his things.

View File

@ -241,7 +241,7 @@ namespace controllers\publics;
if ($how_many_more > 0)
{
$result_text .= ", et $how_many_more autres.";
$result_text .= ", et {$how_many_more} autres.";
}
$return['result'] = $result_text;

View File

@ -87,7 +87,7 @@ namespace controllers\publics;
}
/**
* This function will delete a list of contacts depending on a condition
* This function will delete a list of contacts depending on a condition.
*
* @param string $_POST['condition'] : Condition to use to delete contacts
* @param mixed $csrf
@ -338,11 +338,11 @@ namespace controllers\publics;
break;
default:
if ($read_file['extension'] === 'csv')
if ('csv' === $read_file['extension'])
{
$result = $this->internal_contact->import_csv($id_user, $read_file['content']);
}
elseif ($read_file['extension'] === 'json')
elseif ('json' === $read_file['extension'])
{
$result = $this->internal_contact->import_json($id_user, $read_file['content']);
}

View File

@ -62,7 +62,6 @@ namespace controllers\publics;
$nb_sendeds = $this->internal_sended->count_for_user($id_user);
$nb_receiveds = $this->internal_received->count_for_user($id_user);
//Récupération des 10 derniers Sms envoyés, Sms reçus et evenements enregistrés. Par date.
$sendeds = $this->internal_sended->get_lasts_by_date_for_user($id_user, 10);
$receiveds = $this->internal_received->get_lasts_by_date_for_user($id_user, 10);

View File

@ -133,7 +133,6 @@ namespace controllers\publics;
'status' => $sended['status'],
];
$messages[] = $message;
}
@ -259,7 +258,7 @@ namespace controllers\publics;
//Remove empty files input
foreach ($files_arrays as $key => $file)
{
if ($file['error'] === UPLOAD_ERR_NO_FILE)
if (UPLOAD_ERR_NO_FILE === $file['error'])
{
unset($files_arrays[$key]);
}
@ -288,7 +287,6 @@ namespace controllers\publics;
$id_phone = null;
}
//If mms is enable and we have medias uploaded
$media_ids = [];
if ($_SESSION['user']['settings']['mms'] && $files_arrays)

View File

@ -285,7 +285,7 @@ namespace controllers\publics;
//Remove empty files input
foreach ($files_arrays as $key => $file)
{
if ($file['error'] === UPLOAD_ERR_NO_FILE)
if (UPLOAD_ERR_NO_FILE === $file['error'])
{
unset($files_arrays[$key]);
}
@ -339,6 +339,7 @@ namespace controllers\publics;
catch (\Exception $e)
{
\FlashMessage\FlashMessage::push('danger', 'Impossible d\'upload et d\'enregistrer le fichier ' . $file['name'] . ':' . $e->getMessage());
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
}
@ -423,7 +424,7 @@ namespace controllers\publics;
//Remove empty files input
foreach ($files_arrays as $key => $file)
{
if ($file['error'] === UPLOAD_ERR_NO_FILE)
if (UPLOAD_ERR_NO_FILE === $file['error'])
{
unset($files_arrays[$key]);
}
@ -488,7 +489,7 @@ namespace controllers\publics;
$mms = (bool) count($media_ids);
$this->internal_scheduled->update_for_user($id_user, $id_scheduled, $at, $text, $id_phone, $flash, $mms, $numbers, $contacts, $groups, $conditional_groups, $media_ids);
$nb_update++;
++$nb_update;
}
if ($nb_update !== \count($scheduleds))

View File

@ -57,7 +57,7 @@ namespace controllers\publics;
$allow_no_value = $_POST['allow_no_value'] ?? false;
//if no value allowed and no value fund, default to ''
if ($allow_no_value && ($setting_value === false))
if ($allow_no_value && (false === $setting_value))
{
$setting_value = '';
}

View File

@ -88,7 +88,6 @@ namespace controllers\publics;
$return['result'] = 'Message vide, il ne sera pas envoyé.';
}
//Add credit estimation
$return['estimation_credit'] = $this->internal_quota->compute_credits_for_message($return['result']);

View File

@ -163,7 +163,7 @@ class User extends \descartes\Controller
* @param optional string $_POST['password'] : User password, (if empty the password is randomly generated)
* @param optional boolean $_POST['admin'] : If true user is admin
* @param optional boolean $_POST['quota_enable'] : If true create a quota for the user
* @param boolean $_POST['quota_enable'] : If true create a quota for the user
* @param bool $_POST['quota_enable'] : If true create a quota for the user
* @param optional int $_POST['quota_credit'] : credit for quota
* @param optional int $_POST['quota_additional'] : additional credit
* @param optional string $_POST['quota_start_date'] : quota beginning date
@ -194,7 +194,6 @@ class User extends \descartes\Controller
$quota_report_unused = $_POST['quota_report_unused'] ?? false;
$quota_report_unused_additional = $_POST['quota_report_unused_additional'] ?? false;
if (!$email)
{
\FlashMessage\FlashMessage::push('danger', 'Vous devez au moins fournir une adresse e-mail pour l\'utilisateur.');
@ -209,7 +208,6 @@ class User extends \descartes\Controller
return $this->redirect(\descartes\Router::url('User', 'add'));
}
//Forge quota for user if needed
$quota = null;
if ($quota_enable)
@ -218,7 +216,7 @@ class User extends \descartes\Controller
$quota['credit'] = (int) $quota_credit;
$quota['additional'] = (int) $quota_additional;
if ($quota_start_date === false || !\controllers\internals\Tool::validate_date($quota_start_date, 'Y-m-d H:i:s'))
if (false === $quota_start_date || !\controllers\internals\Tool::validate_date($quota_start_date, 'Y-m-d H:i:s'))
{
\FlashMessage\FlashMessage::push('danger', 'Vous devez définir une date de début valide pour le quota.');
@ -226,7 +224,7 @@ class User extends \descartes\Controller
}
$quota['start_date'] = new \DateTime($quota_start_date);
if ($quota_renew_interval === false || !\controllers\internals\Tool::validate_period($quota_renew_interval))
if (false === $quota_renew_interval || !\controllers\internals\Tool::validate_period($quota_renew_interval))
{
\FlashMessage\FlashMessage::push('danger', 'Vous devez définir une durée de quota parmis la liste proposée.');
@ -242,7 +240,6 @@ class User extends \descartes\Controller
$quota['report_unused_additional'] = (bool) $quota_report_unused_additional;
}
$id_user = $this->internal_user->create($email, $password, $admin, null, \models\User::STATUS_ACTIVE, true, $quota);
if (!$id_user)
{
@ -251,7 +248,6 @@ class User extends \descartes\Controller
return $this->redirect(\descartes\Router::url('User', 'add'));
}
$mailer = new \controllers\internals\Mailer();
$email_send = $mailer->enqueue($email, EMAIL_CREATE_USER, ['email' => $email, 'password' => $password]);
if (!$email_send)
@ -265,7 +261,7 @@ class User extends \descartes\Controller
}
/**
* Return the edition page for the users
* Return the edition page for the users.
*
* @param int... $ids : users ids
*/
@ -295,9 +291,8 @@ class User extends \descartes\Controller
]);
}
/**
* Update a list of users
* Update a list of users.
*
* @param $csrf : Le jeton CSRF
* @param array $_POST['users'] : Array of the users and new values, id as key. Quota may also be defined.
@ -343,7 +338,6 @@ class User extends \descartes\Controller
return $this->redirect(\descartes\Router::url('User', 'add'));
}
//Forge quota for user if needed
$quota = false;
if ($quota_enable)
@ -353,7 +347,7 @@ class User extends \descartes\Controller
$quota['consumed'] = (int) $quota_consumed;
$quota['additional'] = (int) $quota_additional;
if ($quota_start_date === false || !\controllers\internals\Tool::validate_date($quota_start_date, 'Y-m-d H:i:s'))
if (false === $quota_start_date || !\controllers\internals\Tool::validate_date($quota_start_date, 'Y-m-d H:i:s'))
{
\FlashMessage\FlashMessage::push('danger', 'L\'utilisateur #' . (int) $id_user . ' n\'as pas pu être mis à jour car la date de début du quota associé n\'est pas valide.');
@ -361,7 +355,7 @@ class User extends \descartes\Controller
}
$quota['start_date'] = new \DateTime($quota_start_date);
if ($quota_renew_interval === false || !\controllers\internals\Tool::validate_period($quota_renew_interval))
if (false === $quota_renew_interval || !\controllers\internals\Tool::validate_period($quota_renew_interval))
{
\FlashMessage\FlashMessage::push('danger', 'L\'utilisateur #' . (int) $id_user . ' n\'as pas pu être mis à jour car la durée du quota associé n\'est pas valide.');
@ -376,13 +370,11 @@ class User extends \descartes\Controller
$quota['report_unused'] = (bool) $quota_report_unused;
$quota['report_unused_additional'] = (bool) $quota_report_unused_additional;
//Format dates
$quota['start_date'] = $quota['start_date']->format('Y-m-d H:i:s');
$quota['expiration_date'] = $quota['expiration_date']->format('Y-m-d H:i:s');
}
$updated_user = [
'email' => $email,
'admin' => $admin,
@ -401,7 +393,7 @@ class User extends \descartes\Controller
continue;
}
$nb_update++;
++$nb_update;
}
if ($nb_update != count($users))

View File

@ -12,7 +12,7 @@
namespace models;
/**
* Manage bdd operations for calls
* Manage bdd operations for calls.
*/
class Call extends StandardModel
{
@ -62,7 +62,7 @@ namespace models;
}
/**
* Get a call for a user by his phone and uid
* Get a call for a user by his phone and uid.
*
* @param int $id_user : user id
* @param int $id_phone : phone id

View File

@ -27,7 +27,7 @@ namespace models;
}
/**
* Gets events for a type, since a date and eventually until a date (both included)
* Gets events for a type, since a date and eventually until a date (both included).
*
* @param int $id_user : User id
* @param string $type : Event type we want
@ -36,7 +36,7 @@ namespace models;
*
* @return array
*/
public function get_events_by_type_and_date_for_user (int $id_user, string $type, \DateTime $since, ?\DateTime $until = null)
public function get_events_by_type_and_date_for_user(int $id_user, string $type, \DateTime $since, ?\DateTime $until = null)
{
$where = [
'id_user' => $id_user,
@ -44,7 +44,7 @@ namespace models;
'>=at' => $since->format('Y-m-d H:i:s'),
];
if ($until !== null)
if (null !== $until)
{
$where['<=at'] = $until->format('Y-m-d H:i:s');
}

View File

@ -89,14 +89,14 @@ namespace models;
}
/**
* Link a media to a scheduled
* Link a media to a scheduled.
*
* @param int $id_media : Media id
* @param int $id_scheduled : Scheduled id
*
* @return bool | int
*/
public function insert_media_scheduled (int $id_media, int $id_scheduled)
public function insert_media_scheduled(int $id_media, int $id_scheduled)
{
$entry = [
'id_media' => $id_media,
@ -107,14 +107,14 @@ namespace models;
}
/**
* Link a media to a received
* Link a media to a received.
*
* @param int $id_media : Media id
* @param int $id_received : Scheduled id
*
* @return bool | int
*/
public function insert_media_received (int $id_media, int $id_received)
public function insert_media_received(int $id_media, int $id_received)
{
$entry = [
'id_media' => $id_media,
@ -125,14 +125,14 @@ namespace models;
}
/**
* Link a media to a sended
* Link a media to a sended.
*
* @param int $id_media : Media id
* @param int $id_sended : Scheduled id
*
* @return bool | int
*/
public function insert_media_sended (int $id_media, int $id_sended)
public function insert_media_sended(int $id_media, int $id_sended)
{
$entry = [
'id_media' => $id_media,
@ -143,14 +143,14 @@ namespace models;
}
/**
* Unlink a media of a scheduled
* Unlink a media of a scheduled.
*
* @param int $id_media : Media id
* @param int $id_scheduled : Scheduled id
*
* @return bool | int
*/
public function delete_media_scheduled (int $id_media, int $id_scheduled)
public function delete_media_scheduled(int $id_media, int $id_scheduled)
{
$where = [
'id_media' => $id_media,
@ -161,14 +161,14 @@ namespace models;
}
/**
* Unlink a media of a received
* Unlink a media of a received.
*
* @param int $id_media : Media id
* @param int $id_received : Scheduled id
*
* @return bool | int
*/
public function delete_media_received (int $id_media, int $id_received)
public function delete_media_received(int $id_media, int $id_received)
{
$where = [
'id_media' => $id_media,
@ -179,14 +179,14 @@ namespace models;
}
/**
* Unlink a media of a sended
* Unlink a media of a sended.
*
* @param int $id_media : Media id
* @param int $id_sended : Scheduled id
*
* @return bool | int
*/
public function delete_media_sended (int $id_media, int $id_sended)
public function delete_media_sended(int $id_media, int $id_sended)
{
$where = [
'id_media' => $id_media,
@ -196,15 +196,14 @@ namespace models;
return $this->_delete('media_sended', $where);
}
/**
* Unlink all medias of a scheduled
* Unlink all medias of a scheduled.
*
* @param int $id_scheduled : Scheduled id
*
* @return bool | int
*/
public function delete_all_for_scheduled (int $id_scheduled)
public function delete_all_for_scheduled(int $id_scheduled)
{
$where = [
'id_scheduled' => $id_scheduled,
@ -214,13 +213,13 @@ namespace models;
}
/**
* Unlink all medias of a received
* Unlink all medias of a received.
*
* @param int $id_received : Scheduled id
*
* @return bool | int
*/
public function delete_all_for_received (int $id_received)
public function delete_all_for_received(int $id_received)
{
$where = [
'id_received' => $id_received,
@ -230,13 +229,13 @@ namespace models;
}
/**
* Unlink all medias of a sended
* Unlink all medias of a sended.
*
* @param int $id_sended : Scheduled id
*
* @return bool | int
*/
public function delete_all_for_sended (int $id_sended)
public function delete_all_for_sended(int $id_sended)
{
$where = [
'id_sended' => $id_sended,
@ -246,10 +245,11 @@ namespace models;
}
/**
* Find all unused medias
* Find all unused medias.
*
* @return array
*/
public function gets_unused ()
public function gets_unused()
{
$query = '
SELECT `media`.*

View File

@ -27,12 +27,14 @@ namespace models;
/**
* Get remaining credit for a date
* if no quota for this user return max int
* if no quota for this user return max int.
*
* @param int $id_user : User id
* @param \DateTime $at : date to get credit at
*
* @return int : number of remaining credits
*/
public function get_remaining_credit (int $id_user, \DateTime $at): int
public function get_remaining_credit(int $id_user, \DateTime $at): int
{
$query = '
SELECT (credit + additional - consumed) AS remaining_credit
@ -48,17 +50,19 @@ namespace models;
$result = $this->_run_query($query, $params);
return ($result[0]['remaining_credit'] ?? PHP_INT_MAX);
return $result[0]['remaining_credit'] ?? PHP_INT_MAX;
}
/**
* Get credit usage percent for a date
* if no quota for this user return 0
* if no quota for this user return 0.
*
* @param int $id_user : User id
* @param \DateTime $at : date to get usage percent at
*
* @return float : percent of used credits
*/
public function get_usage_percentage (int $id_user, \DateTime $at): float
public function get_usage_percentage(int $id_user, \DateTime $at): float
{
$query = '
SELECT (consumed / (credit + additional)) AS usage_percentage
@ -78,12 +82,14 @@ namespace models;
}
/**
* Consume some credit for a user
* Consume some credit for a user.
*
* @param int $id_user : User id
* @param int $quantity : Number of credits to consume
*
* @return bool
*/
public function consume_credit (int $id_user, int $quantity): int
public function consume_credit(int $id_user, int $quantity): int
{
$query = '
UPDATE quota
@ -98,13 +104,11 @@ namespace models;
return (bool) $this->_run_query($query, $params, \descartes\Model::ROWCOUNT);
}
/**
* Get all quotas we need to send an alert for close limit to users they belongs to
* do not return quotas when user already had an event QUOTA_LIMIT_CLOSE since quota start_date
* @return array
* do not return quotas when user already had an event QUOTA_LIMIT_CLOSE since quota start_date.
*/
public function get_quotas_for_limit_close() : array
public function get_quotas_for_limit_close(): array
{
$query = '
SELECT quota.*
@ -137,10 +141,9 @@ namespace models;
/**
* Get all quotas we need to send an alert for limit reached to users they belongs to
* do not return quotas when user already had an event QUOTA_LIMIT_REACHED since quota start_date
* @return array
* do not return quotas when user already had an event QUOTA_LIMIT_REACHED since quota start_date.
*/
public function get_quotas_for_limit_reached() : array
public function get_quotas_for_limit_reached(): array
{
$query = '
SELECT quota.*
@ -172,11 +175,11 @@ namespace models;
}
/**
* Get list of quotas to be renewed as to a date
* Get list of quotas to be renewed as to a date.
*
* @param \DateTime $at : Date to get quotas to be renewed before
* @return array
*/
public function get_quotas_to_be_renewed (\DateTime $at): array
public function get_quotas_to_be_renewed(\DateTime $at): array
{
$at = $at->format('Y-m-d H:i:s');
$where = [

View File

@ -234,7 +234,6 @@ namespace models;
return $this->_run_query($query, $params);
}
/**
* Get messages scheduled after a date for a number and a user.
*

View File

@ -113,7 +113,6 @@ namespace models;
return $this->_run_query($query, $params);
}
/**
* Return sendeds for an destination and a user since a date.
*

View File

@ -32,7 +32,8 @@ namespace models;
}
/**
* Find user by ids
* Find user by ids.
*
* @param array $ids : users ids
*
* @return array

View File

@ -19,7 +19,6 @@ namespace models;
const TYPE_QUOTA_LEVEL_ALERT = 'quota_level';
const TYPE_QUOTA_REACHED = 'quota_reached';
/**
* Find all webhooks for a user and for a type of webhook.
*