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

@ -23,7 +23,7 @@ namespace adapters;
/**
* Adapter constructor, called when instanciated by RaspiSMS.
*
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/
public function __construct(string $datas);
@ -31,12 +31,12 @@ namespace adapters;
* Classname of the adapter.
*/
public static function meta_classname(): string;
/**
* Uniq name of the adapter
* It should be the classname of the adapter un snakecase
* It should be the classname of the adapter un snakecase.
*/
public static function meta_uid() : string;
public static function meta_uid(): string;
/**
* Name of the adapter.
@ -66,18 +66,17 @@ namespace adapters;
* Does the implemented service support reading smss.
*/
public static function meta_support_read(): bool;
/**
* Does the implemented service support reception callback.
*/
public static function meta_support_reception(): bool;
/**
* Does the implemented service support status change callback.
*/
public static function meta_support_status_change(): bool;
/**
* Method called to send a SMS to a number.
*
@ -86,10 +85,10 @@ namespace adapters;
* @param bool $flash : Is the SMS a Flash SMS
*
* @return array : [
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* ?string 'uid' => Uid of the sms created on success
* ]
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* ?string 'uid' => Uid of the sms created on success
* ]
*/
public function send(string $destination, string $text, bool $flash = false);
@ -97,18 +96,18 @@ namespace adapters;
* Method called to read SMSs of the number.
*
* @return array : [
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'smss' => Array of the sms reads
* [
* [
* string 'at' => sms reception date,
* string 'text' => sms text,
* string 'origin' => phone number who sent the sms
* ],
* ...
* ]
* ]
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'smss' => Array of the sms reads
* [
* [
* string 'at' => sms reception date,
* string 'text' => sms text,
* string 'origin' => phone number who sent the sms
* ],
* ...
* ]
* ]
*/
public function read(): array;
@ -126,20 +125,20 @@ namespace adapters;
* @return mixed : False on error, else array ['uid' => uid of the sms, 'status' => New status of the sms (\models\Sended::STATUS_UNKNOWN, \models\Sended::STATUS_DELIVERED, \models\Sended::STATUS_FAILED)]
*/
public static function status_change_callback();
/**
* Method called on reception of a sms notification.
*
* @return array : [
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
*
* ]
*/
public static function reception_callback() : array;
public static function reception_callback(): array;
}

View file

@ -28,7 +28,7 @@ namespace adapters;
/**
* Adapter constructor, called when instanciated by RaspiSMS.
*
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/
public function __construct(string $datas)
{
@ -42,12 +42,12 @@ namespace adapters;
{
return __CLASS__;
}
/**
* Uniq name of the adapter
* It should be the classname of the adapter un snakecase
* It should be the classname of the adapter un snakecase.
*/
public static function meta_uid() : string
public static function meta_uid(): string
{
return 'gammu_adapter';
}
@ -116,7 +116,7 @@ namespace adapters;
{
return false;
}
/**
* Does the implemented service support reception callback.
*/
@ -125,7 +125,6 @@ namespace adapters;
return false;
}
/**
* Method called to send a SMS to a number.
*
@ -134,10 +133,10 @@ namespace adapters;
* @param bool $flash : Is the SMS a Flash SMS
*
* @return array : [
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* ?string 'uid' => Uid of the sms created on success, null on error
* ]
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* ?string 'uid' => Uid of the sms created on success, null on error
* ]
*/
public function send(string $destination, string $text, bool $flash = false)
{
@ -151,6 +150,7 @@ namespace adapters;
{
$response['error'] = true;
$response['error_message'] = 'Cannot unlock SIM.';
return $response;
}
@ -179,6 +179,7 @@ namespace adapters;
{
$response['error'] = true;
$response['error_message'] = 'Gammu command failed.';
return $response;
}
@ -187,6 +188,7 @@ namespace adapters;
{
$response['error'] = true;
$response['error_message'] = 'Cannot find output OK.';
return $response;
}
@ -208,10 +210,12 @@ namespace adapters;
{
$response['error'] = true;
$response['error_message'] = 'Cannot retrieve sms uid.';
return $response;
}
$response['uid'] = $uid;
return $response;
}
@ -219,10 +223,10 @@ namespace adapters;
* Method called to read SMSs of the number.
*
* @return array : [
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads
* ]
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads
* ]
*/
public function read(): array
{
@ -236,6 +240,7 @@ namespace adapters;
{
$response['error'] = true;
$response['error_message'] = 'Cannot unlock sim.';
return $response;
}
@ -249,6 +254,7 @@ namespace adapters;
{
$response['error'] = true;
$response['error_message'] = 'Gammu command return failed.';
return $response;
}
@ -292,6 +298,25 @@ namespace adapters;
return false;
}
/**
* Method called on reception of a sms notification.
*
* @return array : [
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
*
* ]
*/
public static function reception_callback(): array
{
return [];
}
/**
* Function to unlock pin.
*
@ -376,24 +401,4 @@ namespace adapters;
return (bool) $find;
}
/**
* Method called on reception of a sms notification.
*
* @return array : [
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
*
* ]
*/
public static function reception_callback() : array
{
return [];
}
}

View file

@ -12,7 +12,7 @@
namespace adapters;
/**
* Octopush SMS service with a shortcode adapter
* Octopush SMS service with a shortcode adapter.
*/
class OctopushShortcodeAdapter implements AdapterInterface
{
@ -27,25 +27,25 @@ class OctopushShortcodeAdapter implements AdapterInterface
private $datas;
/**
* Octopush login
* Octopush login.
*/
private $login;
/**
* Octopush api key
* Octopush api key.
*/
private $api_key;
/**
* Sender name to use instead of shortcode
* Sender name to use instead of shortcode.
*/
private $sender;
/**
* Octopush api baseurl
* Octopush api baseurl.
*/
private $api_url = 'https://www.octopush-dm.com/api';
/**
* Adapter constructor, called when instanciated by RaspiSMS.
*
@ -69,12 +69,11 @@ class OctopushShortcodeAdapter implements AdapterInterface
return __CLASS__;
}
/**
* Uniq name of the adapter
* It should be the classname of the adapter un snakecase
* It should be the classname of the adapter un snakecase.
*/
public static function meta_uid() : string
public static function meta_uid(): string
{
return 'octopush_shortcode_adapter';
}
@ -95,6 +94,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
public static function meta_description(): string
{
$credentials_url = 'https://www.octopush-dm.com/api-logins';
return '
Envoi de SMS avec un shortcode en utilisant <a target="_blank" href="https://www.octopush.com/">Octopush</a>. Pour trouver vos clés API Octopush <a target="_blank" href="' . $credentials_url . '">cliquez ici.</a>
';
@ -128,7 +128,6 @@ class OctopushShortcodeAdapter implements AdapterInterface
<b>Si vous utilisez un expéditeur nommé, le destinataire ne pourra pas répondre.</b>',
'required' => false,
],
];
}
@ -172,10 +171,10 @@ class OctopushShortcodeAdapter implements AdapterInterface
* @param bool $flash : Is the SMS a Flash SMS
*
* @return array : [
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'uid' => Uid of the sms created on success
* ]
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'uid' => Uid of the sms created on success
* ]
*/
public function send(string $destination, string $text, bool $flash = false)
{
@ -196,7 +195,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
'sms_type' => self::SMS_TYPE_LOWCOST,
];
if ($this->sender !== null)
if (null !== $this->sender)
{
$datas['sms_sender'] = $this->sender;
}
@ -212,25 +211,28 @@ class OctopushShortcodeAdapter implements AdapterInterface
$response = curl_exec($curl);
curl_close($curl);
if ($response === false)
if (false === $response)
{
$response['error'] = true;
$response['error_message'] = 'HTTP query failed.';
return $response;
}
$response_decode = json_decode($response, true);
if ($response_decode === null)
if (null === $response_decode)
{
$response['error'] = true;
$response['error_message'] = 'Invalid JSON for response.';
return $response;
}
if ($response_decode['error_code'] != self::ERROR_CODE_OK)
if (self::ERROR_CODE_OK !== $response_decode['error_code'])
{
$response['error'] = true;
$response['error_message'] = 'Response indicate error code : ' . $response_decode['error_code'];
return $response;
}
@ -239,16 +241,19 @@ class OctopushShortcodeAdapter implements AdapterInterface
{
$response['error'] = true;
$response['error_message'] = 'Cannot extract SMS uid';
return $response;
}
$response['uid'] = $uid;
return $response;
}
catch (\Throwable $t)
{
$response['error'] = true;
$response['error_message'] = $t->getMessage();
return $response;
}
}
@ -257,10 +262,10 @@ class OctopushShortcodeAdapter implements AdapterInterface
* Method called to read SMSs of the number.
*
* @return array : [
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads
* ]
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads
* ]
*/
public function read(): array
{
@ -283,7 +288,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
{
return false;
}
$datas = [
'user_login' => $this->login,
'api_key' => $this->api_key,
@ -300,18 +305,18 @@ class OctopushShortcodeAdapter implements AdapterInterface
$response = curl_exec($curl);
curl_close($curl);
if ($response === false)
if (false === $response)
{
return false;
}
$response_decode = json_decode($response, true);
if ($response_decode === null)
if (null === $response_decode)
{
return false;
}
if ($response_decode['error_code'] != self::ERROR_CODE_OK)
if (self::ERROR_CODE_OK !== $response_decode['error_code'])
{
return false;
}
@ -338,7 +343,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
$uid = $_POST['message_id'] ?? false;
$status = $_POST['status'] ?? false;
if ($uid === false || $status === false)
if (false === $uid || false === $status)
{
return false;
}
@ -347,40 +352,40 @@ class OctopushShortcodeAdapter implements AdapterInterface
{
case 'DELIVERED':
$status = \models\Sended::STATUS_DELIVERED;
break;
case 'NOT_ALLOWED':
case 'INVALID_DESTINATION_ADDRESS':
case 'OUT_OF_DATE':
case 'EXPIRED':
case 'BLACKLISTED_NUMBER':
$status = \models\Sended::STATUS_FAILED;
break;
default :
break;
default:
$status = \models\Sended::STATUS_UNKNOWN;
break;
}
return ['uid' => $uid, 'status' => $status];
}
/**
* Method called on reception of a sms notification.
*
* @return array : [
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
*
* ]
*/
public static function reception_callback() : array
public static function reception_callback(): array
{
$response = [
'error' => false,
@ -400,6 +405,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
{
$response['error'] = true;
$response['error_message'] = 'One required data of the callback is missing.';
return $response;
}
@ -408,6 +414,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
{
$response['error'] = true;
$response['error_message'] = 'Invalid origin number : ' . mb_substr($number, 2);
return $response;
}
@ -416,6 +423,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
'text' => $text,
'origin' => $origin,
];
return $response;
}
}

View file

@ -12,7 +12,7 @@
namespace adapters;
/**
* Octopush SMS service with a shortcode adapter
* Octopush SMS service with a shortcode adapter.
*/
class OctopushVirtualNumberAdapter implements AdapterInterface
{
@ -27,30 +27,30 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
private $datas;
/**
* Octopush login
* Octopush login.
*/
private $login;
/**
* Octopush api key
* Octopush api key.
*/
private $api_key;
/**
* Number phone to use
* Number phone to use.
*/
private $number;
/**
* Number phone to use formated for octopush compatibility
* Number phone to use formated for octopush compatibility.
*/
private $formatted_number;
/**
* Octopush api baseurl
* Octopush api baseurl.
*/
private $api_url = 'https://www.octopush-dm.com/api';
/**
* Adapter constructor, called when instanciated by RaspiSMS.
*
@ -75,12 +75,11 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
return __CLASS__;
}
/**
* Uniq name of the adapter
* It should be the classname of the adapter un snakecase
* It should be the classname of the adapter un snakecase.
*/
public static function meta_uid() : string
public static function meta_uid(): string
{
return 'octopush_virtual_number_adapter';
}
@ -101,6 +100,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
public static function meta_description(): string
{
$credentials_url = 'https://www.octopush-dm.com/api-logins';
return '
Envoi de SMS avec un numéro virtuel en utilisant <a target="_blank" href="https://www.octopush.com/">Octopush</a>. Pour trouver vos clés API Octopush <a target="_blank" href="' . $credentials_url . '">cliquez ici.</a>
';
@ -133,7 +133,6 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
'required' => true,
'number' => true,
],
];
}
@ -177,10 +176,10 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
* @param bool $flash : Is the SMS a Flash SMS
*
* @return array : [
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'uid' => Uid of the sms created on success
* ]
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'uid' => Uid of the sms created on success
* ]
*/
public function send(string $destination, string $text, bool $flash = false)
{
@ -212,25 +211,28 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
$response = curl_exec($curl);
curl_close($curl);
if ($response === false)
if (false === $response)
{
$response['error'] = true;
$response['error_message'] = 'HTTP query failed.';
return $response;
}
$response_decode = json_decode($response, true);
if ($response_decode === null)
if (null === $response_decode)
{
$response['error'] = true;
$response['error_message'] = 'Invalid JSON for response.';
return $response;
}
if ($response_decode['error_code'] != self::ERROR_CODE_OK)
if (self::ERROR_CODE_OK !== $response_decode['error_code'])
{
$response['error'] = true;
$response['error_message'] = 'Response indicate error code : ' . $response_decode['error_code'];
return $response;
}
@ -239,16 +241,19 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
{
$response['error'] = true;
$response['error_message'] = 'Cannot extract SMS uid';
return $response;
}
$response['uid'] = $uid;
return $response;
}
catch (\Throwable $t)
{
$response['error'] = true;
$response['error_message'] = $t->getMessage();
return $response;
}
}
@ -257,10 +262,10 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
* Method called to read SMSs of the number.
*
* @return array : [
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads
* ]
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads
* ]
*/
public function read(): array
{
@ -283,7 +288,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
{
return false;
}
$datas = [
'user_login' => $this->login,
'api_key' => $this->api_key,
@ -300,18 +305,18 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
$response = curl_exec($curl);
curl_close($curl);
if ($response === false)
if (false === $response)
{
return false;
}
$response_decode = json_decode($response, true);
if ($response_decode === null)
if (null === $response_decode)
{
return false;
}
if ($response_decode['error_code'] != self::ERROR_CODE_OK)
if (self::ERROR_CODE_OK !== $response_decode['error_code'])
{
return false;
}
@ -338,7 +343,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
$uid = $_POST['message_id'] ?? false;
$status = $_POST['status'] ?? false;
if ($uid === false || $status === false)
if (false === $uid || false === $status)
{
return false;
}
@ -347,40 +352,40 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
{
case 'DELIVERED':
$status = \models\Sended::STATUS_DELIVERED;
break;
case 'NOT_ALLOWED':
case 'INVALID_DESTINATION_ADDRESS':
case 'OUT_OF_DATE':
case 'EXPIRED':
case 'BLACKLISTED_NUMBER':
$status = \models\Sended::STATUS_FAILED;
break;
default :
break;
default:
$status = \models\Sended::STATUS_UNKNOWN;
break;
}
return ['uid' => $uid, 'status' => $status];
}
/**
* Method called on reception of a sms notification.
*
* @return array : [
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
*
* ]
*/
public static function reception_callback() : array
public static function reception_callback(): array
{
$response = [
'error' => false,
@ -400,6 +405,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
{
$response['error'] = true;
$response['error_message'] = 'One required data of the callback is missing.';
return $response;
}
@ -408,6 +414,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
{
$response['error'] = true;
$response['error_message'] = 'Invalid origin number : ' . mb_substr($number, 2);
return $response;
}
@ -416,6 +423,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
'text' => $text,
'origin' => $origin,
];
return $response;
}
}

View file

@ -14,7 +14,7 @@ namespace adapters;
use Ovh\Api;
/**
* OVH SMS service with a shortcode allowing responses
* OVH SMS service with a shortcode allowing responses.
*/
class OvhSmsShortcodeAdapter implements AdapterInterface
{
@ -56,9 +56,9 @@ namespace adapters;
/**
* Uniq name of the adapter
* It should be the classname of the adapter un snakecase
* It should be the classname of the adapter un snakecase.
*/
public static function meta_uid() : string
public static function meta_uid(): string
{
return 'ovh_sms_shortcode_adapter';
}
@ -151,7 +151,7 @@ namespace adapters;
{
return true;
}
/**
* Does the implemented service support reception callback.
*/
@ -160,7 +160,6 @@ namespace adapters;
return false;
}
/**
* Method called to send a SMS to a number.
*
@ -169,10 +168,10 @@ namespace adapters;
* @param bool $flash : Is the SMS a Flash SMS
*
* @return array : [
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* ?string 'uid' => Uid of the sms created on success
* ]
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* ?string 'uid' => Uid of the sms created on success
* ]
*/
public function send(string $destination, string $text, bool $flash = false)
{
@ -206,6 +205,7 @@ namespace adapters;
{
$response['error'] = true;
$response['error_message'] = 'Invalid receiver';
return $response;
}
@ -214,16 +214,19 @@ namespace adapters;
{
$response['error'] = true;
$response['error_message'] = 'Cannot retrieve uid.';
return $response;
}
$response['uid'] = $uid;
return $response;
}
catch (\Throwable $t)
{
$response['error'] = true;
$response['error_message'] = $t->getMessage();
return $response;
}
}
@ -232,10 +235,10 @@ namespace adapters;
* Method called to read SMSs of the number.
*
* @return array : [
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads
* ]
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads
* ]
*/
public function read(): array
{
@ -288,6 +291,7 @@ namespace adapters;
{
$response['error'] = true;
$response['error_message'] = $t->getMessage();
return $response;
}
}
@ -303,7 +307,7 @@ namespace adapters;
try
{
$success = true;
if ($this->datas['sender'] && (mb_strlen($this->datas['sender']) < 3 || mb_strlen($this->datas['sender'] > 11)))
{
return false;
@ -312,9 +316,8 @@ namespace adapters;
//Check service name
$endpoint = '/sms/' . $this->datas['service_name'];
$response = $this->api->get($endpoint);
$success = $success && (bool) $response;
return $success;
return $success && (bool) $response;
}
catch (\Throwable $t)
{
@ -356,23 +359,22 @@ namespace adapters;
return ['uid' => $uid, 'status' => $status];
}
/**
* Method called on reception of a sms notification.
*
* @return array : [
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
*
* ]
*/
public static function reception_callback() : array
public static function reception_callback(): array
{
return [];
}

View file

@ -14,7 +14,7 @@ namespace adapters;
use Ovh\Api;
/**
* OVH SMS service with a virtual number adapter
* OVH SMS service with a virtual number adapter.
*/
class OvhSmsVirtualNumberAdapter implements AdapterInterface
{
@ -29,7 +29,7 @@ namespace adapters;
private $api;
/**
* Number used
* Number used.
*/
private $number;
@ -41,7 +41,7 @@ namespace adapters;
/**
* Adapter constructor, called when instanciated by RaspiSMS.
*
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/
public function __construct(string $datas)
{
@ -53,7 +53,7 @@ namespace adapters;
'ovh-eu',
$this->datas['consumer_key']
);
$this->number = $this->datas['number'];
$this->formatted_number = str_replace('+', '00', $this->number);
}
@ -65,13 +65,12 @@ namespace adapters;
{
return __CLASS__;
}
/**
* Uniq name of the adapter
* It should be the classname of the adapter un snakecase
* It should be the classname of the adapter un snakecase.
*/
public static function meta_uid() : string
public static function meta_uid(): string
{
return 'ovh_sms_virtual_number_adapter';
}
@ -180,10 +179,10 @@ namespace adapters;
* @param bool $flash : Is the SMS a Flash SMS
*
* @return array : [
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'uid' => Uid of the sms created on success
* ]
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'uid' => Uid of the sms created on success
* ]
*/
public function send(string $destination, string $text, bool $flash = false)
{
@ -210,6 +209,7 @@ namespace adapters;
{
$response['error'] = true;
$response['error_message'] = 'Invalid receiver';
return $response;
}
@ -218,16 +218,19 @@ namespace adapters;
{
$response['error'] = true;
$response['error_message'] = 'Cannot retrieve uid';
return $response;
}
$response['uid'] = $uid;
return $response;
}
catch (\Throwable $t)
{
$response['error'] = true;
$response['error_message'] = $t->getMessage();
return $response;
}
}
@ -236,10 +239,10 @@ namespace adapters;
* Method called to read SMSs of the number.
*
* @return array : [
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads
* ]
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads
* ]
*/
public function read(): array
{
@ -253,8 +256,8 @@ namespace adapters;
{
$endpoint = '/sms/' . $this->datas['service_name'] . '/virtualNumbers/' . $this->formatted_number . '/incoming';
$uids = $this->api->get($endpoint);
if (!is_array($uids) || !$uids)
if (!\is_array($uids) || !$uids)
{
return $response;
}
@ -286,6 +289,7 @@ namespace adapters;
{
$response['error'] = true;
$response['error_message'] = $t->getMessage();
return $response;
}
}
@ -354,22 +358,22 @@ namespace adapters;
return ['uid' => $uid, 'status' => $status];
}
/**
* Method called on reception of a sms notification.
*
* @return array : [
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
*
* ]
*/
public static function reception_callback() : array
public static function reception_callback(): array
{
return [];
}

View file

@ -38,7 +38,7 @@ namespace adapters;
/**
* Adapter constructor, called when instanciated by RaspiSMS.
*
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/
public function __construct(string $datas)
{
@ -52,12 +52,12 @@ namespace adapters;
{
return __CLASS__;
}
/**
* Uniq name of the adapter
* It should be the classname of the adapter un snakecase
* It should be the classname of the adapter un snakecase.
*/
public static function meta_uid() : string
public static function meta_uid(): string
{
return 'test_adapter';
}
@ -89,8 +89,7 @@ namespace adapters;
{
return [];
}
/**
* Does the implemented service support reading smss.
*/
@ -131,10 +130,10 @@ namespace adapters;
* @param bool $flash : Is the SMS a Flash SMS
*
* @return array : [
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'uid' => Uid of the sms created on success
* ]
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'uid' => Uid of the sms created on success
* ]
*/
public function send(string $destination, string $text, bool $flash = false)
{
@ -148,15 +147,16 @@ namespace adapters;
$at = (new \DateTime())->format('Y-m-d H:i:s');
$success = file_put_contents($this->test_file_write, json_encode(['uid' => $uid, 'at' => $at, 'destination' => $destination, 'text' => $text, 'flash' => $flash]) . "\n", FILE_APPEND);
if ($success === false)
if (false === $success)
{
$response['error'] = true;
$response['error_message'] = 'Cannot write in file : ' . $this->test_file_write;
return $response;
}
$response['uid'] = $uid;
return $response;
}
@ -164,10 +164,10 @@ namespace adapters;
* Method called to read SMSs of the number.
*
* @return array : [
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads
* ]
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads
* ]
*/
public function read(): array
{
@ -177,22 +177,24 @@ namespace adapters;
'smss' => [],
];
try
try
{
$file_contents = file_get_contents($this->test_file_read);
if ($file_contents === false)
if (false === $file_contents)
{
$response['error'] = true;
$response['error_message'] = 'Cannot read file : ' . $this->test_file_read;
return $response;
}
//Empty file to avoid dual read
$success = file_put_contents($this->test_file_read, '');
if ($success === false)
if (false === $success)
{
$response['error'] = true;
$response['error_message'] = 'Cannot write in file : ' . $this->test_file_read;
return $response;
}
@ -215,6 +217,7 @@ namespace adapters;
{
$response['error'] = true;
$response['error_message'] = $t->getMessage();
return $response;
}
}
@ -232,7 +235,6 @@ namespace adapters;
/**
* Method called on reception of a status update notification for a SMS.
*
*/
public static function status_change_callback()
{
@ -267,23 +269,22 @@ namespace adapters;
return $return;
}
/**
* Method called on reception of a sms notification.
*
* @return array : [
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
*
* ]
*/
public static function reception_callback() : array
public static function reception_callback(): array
{
return [];
}

View file

@ -14,7 +14,7 @@ namespace adapters;
use Twilio\Rest\Client;
/**
* Twilio SMS service with a virtual number adapter
* Twilio SMS service with a virtual number adapter.
*/
class TwilioVirtualNumberAdapter implements AdapterInterface
{
@ -24,17 +24,17 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
private $datas;
/**
* Twilio Api client
* Twilio Api client.
*/
private $client;
/**
* Twilio virtual number to use
* Twilio virtual number to use.
*/
private $number;
/**
* Callback address Twilio must call on SMS status change
* Callback address Twilio must call on SMS status change.
*/
private $status_change_callback;
@ -65,12 +65,11 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
return __CLASS__;
}
/**
* Uniq name of the adapter
* It should be the classname of the adapter un snakecase
* It should be the classname of the adapter un snakecase.
*/
public static function meta_uid() : string
public static function meta_uid(): string
{
return 'twilio_virtual_number_adapter';
}
@ -174,10 +173,10 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
* @param bool $flash : Is the SMS a Flash SMS
*
* @return array : [
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'uid' => Uid of the sms created on success
* ]
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'uid' => Uid of the sms created on success
* ]
*/
public function send(string $destination, string $text, bool $flash = false)
{
@ -198,20 +197,23 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
]
);
if ($message->errorCode !== null)
if (null !== $message->errorCode)
{
$response['error'] = true;
$response['error_message'] = $message->errorMessage;
return $response;
}
$response['uid'] = $message->sid;
return $response;
}
catch (\Throwable $t)
{
$response['error'] = true;
$response['error_message'] = $t->getMessage();
return $response;
}
}
@ -220,10 +222,10 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
* Method called to read SMSs of the number.
*
* @return array : [
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads
* ]
* bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message
* array 'sms' => Array of the sms reads
* ]
*/
public function read(): array
{
@ -241,7 +243,7 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
foreach ($messages as $record)
{
if ($record->direction != 'inbound')
if ('inbound' !== $record->direction)
{
continue;
}
@ -265,6 +267,7 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
{
$response['error'] = true;
$response['error_message'] = $t->getMessage();
return $response;
}
}
@ -284,7 +287,7 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
foreach ($phone_numbers as $record)
{
//If not the same number, return false
if ($record->phoneNumber != $this->number)
if ($record->phoneNumber !== $this->number)
{
continue;
}
@ -317,16 +320,17 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
switch ($status)
{
case 'delivered' :
case 'delivered':
$status = \models\Sended::STATUS_DELIVERED;
break;
case 'failed' :
break;
case 'failed':
$status = \models\Sended::STATUS_FAILED;
break;
default :
break;
default:
$status = \models\Sended::STATUS_UNKNOWN;
break;
}
@ -337,17 +341,17 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
* Method called on reception of a sms notification.
*
* @return array : [
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
* bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else
* array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body,
* string 'origin' : SMS sender,
* ]
*
* ]
*/
public static function reception_callback() : array
public static function reception_callback(): array
{
return [];
}