From 5f1f5ba5162d38573594735ebaaf374cf7c547bc Mon Sep 17 00:00:00 2001 From: Norris Oduro Date: Thu, 5 Oct 2017 11:26:23 +0000 Subject: [PATCH] fix code style --- src/Exceptions/CouldNotSendNotification.php | 6 ++-- src/Exceptions/InvalidConfiguration.php | 4 +-- src/HubtelChannel.php | 14 +++----- src/HubtelMessage.php | 40 ++++++++++----------- src/SMSClients/HubtelSMSClient.php | 24 ++++++------- src/config/hubtel.php | 7 ++-- tests/HubtelMessageTest.php | 38 ++++++++++---------- 7 files changed, 63 insertions(+), 70 deletions(-) diff --git a/src/Exceptions/CouldNotSendNotification.php b/src/Exceptions/CouldNotSendNotification.php index 16c8313..4a0d07b 100644 --- a/src/Exceptions/CouldNotSendNotification.php +++ b/src/Exceptions/CouldNotSendNotification.php @@ -6,16 +6,16 @@ class CouldNotSendNotification extends \Exception { public static function recipientNotSetError() { - return new static("Recipient phone number not set"); + return new static('Recipient phone number not set'); } public static function senderNotSetError() { - return new static("Sender phone number not set"); + return new static('Sender phone number not set'); } public static function contentNotSetError() { - return new static("Message content empty"); + return new static('Message content empty'); } } diff --git a/src/Exceptions/InvalidConfiguration.php b/src/Exceptions/InvalidConfiguration.php index 1245c8b..c1999c7 100644 --- a/src/Exceptions/InvalidConfiguration.php +++ b/src/Exceptions/InvalidConfiguration.php @@ -6,11 +6,11 @@ class InvalidConfiguration extends \Exception { public static function apiKeyNotSet() { - return new static("Hubtel API key not set"); + return new static('Hubtel API key not set'); } public static function apiSecretNotSet() { - return new static ("Hubtel API secret not set"); + return new static ('Hubtel API secret not set'); } } \ No newline at end of file diff --git a/src/HubtelChannel.php b/src/HubtelChannel.php index 5d91f3a..d6d513a 100644 --- a/src/HubtelChannel.php +++ b/src/HubtelChannel.php @@ -30,26 +30,22 @@ public function send($notifiable, Notification $notification) { $message = $notification->toSMS($notifiable); - if(is_null($message->from)) - { + if (is_null($message->from)) { throw CouldNotSendNotification::senderNotSetError(); } - if(is_null($message->to) && is_null($notifiable->routeNotificationFor('SMS'))) - { + if (is_null($message->to) && is_null($notifiable->routeNotificationFor('SMS'))) { throw CouldNotSendNotification::recipientNotSetError(); } - if(is_null($message->content)) - { + if (is_null($message->content)) { throw CouldNotSendNotification::contentNotSetError(); } - if(is_null($message->to) && !is_null($notifiable->routeNotificationFor('SMS'))) - { + if (is_null($message->to) && !is_null($notifiable->routeNotificationFor('SMS'))) { $message->to = $notifiable->routeNotificationFor('SMS'); } - return $this->client->send($message); + return $this->client->send($message); } } diff --git a/src/HubtelMessage.php b/src/HubtelMessage.php index ad57beb..ff04edc 100644 --- a/src/HubtelMessage.php +++ b/src/HubtelMessage.php @@ -5,19 +5,19 @@ class HubtelMessage { /** - * Sender's phone number + * Sender's phone number. * @var string */ public $from; /** - * Recipient phone number + * Recipient phone number. * @var string */ public $to; /** - * Message + * Message. * @var string */ public $content; @@ -30,31 +30,31 @@ class HubtelMessage /** *The Reference Number provided by the Client - *prior to sending the message + *prior to sending the message. *@var int */ public $clientReference; /** - * Indicates the type of message to be sent + * Indicates the type of message to be sent. *@var int */ public $type; /** - *The User Data Header of the SMS Message being sent + *The User Data Header of the SMS Message being sent. *@var string */ public $udh; /** - *Indicates when to send the message + *Indicates when to send the message. *@var mixed */ public $time; /** - *Indicates if this message must be sent as a flash message + *Indicates if this message must be sent as a flash message. *@var bool */ public $flashMessage; @@ -68,7 +68,7 @@ public function __construct($from = null, $to = null, $content = null) } /** - * Set the message sender's phone number + * Set the message sender's phone number. * @param string $from * @return $this */ @@ -79,7 +79,7 @@ public function from($from) } /** - * Set the recipient's phone number + * Set the recipient's phone number. * @param string $to * @return $this */ @@ -90,7 +90,7 @@ public function to($to) } /** - * Set the message content + * Set the message content. * @param string $content * @return $this */ @@ -101,17 +101,17 @@ public function content($content) } /** - *Set delivery report status + *Set delivery report status. * @return $this */ public function registeredDelivery() { - $this->registeredDelivery = "true"; + $this->registeredDelivery = 'true'; return $this; } /** - * Set the client reference number + * Set the client reference number. * @param int $reference * @return $this */ @@ -122,7 +122,7 @@ public function clientReference($reference) } /** - * Set the message type + * Set the message type. * @param int $type * @return $this */ @@ -133,7 +133,7 @@ public function type($type) } /** - * Set the User Data Header of the SMS Message + * Set the User Data Header of the SMS Message. * @param string $udh * @return $this */ @@ -144,23 +144,23 @@ public function udh($udh) } /** - * Set the time to send the message + * Set the time to send the message. * @param mixed $time * @return $this */ public function time($time) { - $this->time =$time; + $this->time = $time; return $this; } /** - * Set message as a flash message + * Set message as a flash message. * @return $this */ public function flashMessage() { - $this->flashMessage = "true"; + $this->flashMessage = 'true'; return $this; } } diff --git a/src/SMSClients/HubtelSMSClient.php b/src/SMSClients/HubtelSMSClient.php index d364a91..50a03d1 100644 --- a/src/SMSClients/HubtelSMSClient.php +++ b/src/SMSClients/HubtelSMSClient.php @@ -15,7 +15,7 @@ class HubtelSMSClient public $apiSecret; - public function __construct($apiKey,$apiSecret,Client $client) + public function __construct($apiKey, $apiSecret, Client $client) { $this->apiKey = $apiKey; $this->apiSecret = $apiSecret; @@ -24,7 +24,7 @@ public function __construct($apiKey,$apiSecret,Client $client) public function send(HubtelMessage $message) { - return $this->client->get($this->getApiURL().$this->buildMessage($message,$this->apiKey,$this->apiSecret)); + return $this->client->get($this->getApiURL().$this->buildMessage($message, $this->apiKey, $this->apiSecret)); } public function getApiURL() @@ -32,16 +32,14 @@ public function getApiURL() return 'https://api.hubtel.com/v1/messages/send?'; } - public function buildMessage(HubtelMessage $message,$apiKey,$apiSecret) + public function buildMessage(HubtelMessage $message, $apiKey, $apiSecret) { - $this->validateConfig($apiKey,$apiSecret); + $this->validateConfig($apiKey, $apiSecret); - $params = array("ClientId"=>$apiKey,"ClientSecret" => $apiSecret); + $params = array('ClientId'=>$apiKey,'ClientSecret' => $apiSecret); - foreach(get_object_vars($message) as $property => $value) - { - if(!is_null($value)) - { + foreach(get_object_vars($message) as $property => $value) { + if(!is_null($value)) { $params[ucfirst($property)] = $value; } } @@ -49,15 +47,13 @@ public function buildMessage(HubtelMessage $message,$apiKey,$apiSecret) return http_build_query($params); } - public function validateConfig($apiKey,$apiSecret) + public function validateConfig($apiKey, $apiSecret) { - if(is_null($apiKey)) - { + if(is_null($apiKey)) { throw InvalidConfiguration::apiKeyNotSet(); } - if(is_null($apiSecret)) - { + if(is_null($apiSecret)) { throw InvalidConfiguration::apiSecretNotSet(); } return $this; diff --git a/src/config/hubtel.php b/src/config/hubtel.php index 72670a2..3fb0abd 100644 --- a/src/config/hubtel.php +++ b/src/config/hubtel.php @@ -1,11 +1,12 @@ [ 'key' => env('HUBTEL_API_KEY'), - 'secret' => env('HUBTEL_API_SECRET') - ] + 'secret' => env('HUBTEL_API_SECRET'), + ], + ]; \ No newline at end of file diff --git a/tests/HubtelMessageTest.php b/tests/HubtelMessageTest.php index 3a2f0ab..6e47a68 100644 --- a/tests/HubtelMessageTest.php +++ b/tests/HubtelMessageTest.php @@ -18,72 +18,72 @@ public function setUp() /** @test **/ public function it_can_construct_the_message_with_the_basic_required_parameters() { - $message = new HubtelMessage("Norris","1234567890","Hello There"); - $this->assertEquals($message->from,"Norris"); - $this->assertEquals($message->to,"1234567890"); - $this->assertEquals($message->content,"Hello There"); + $message = new HubtelMessage('Norris', '1234567890', 'Hello There'); + $this->assertEquals($message->from, 'Norris'); + $this->assertEquals($message->to, '1234567890'); + $this->assertEquals($message->content, 'Hello There'); } /** @test **/ public function it_can_set_the_message_sender_from_a_method() { - $this->message->from("Norris"); - $this->assertEquals($this->message->from,"Norris"); + $this->message->from('Norris'); + $this->assertEquals($this->message->from, 'Norris'); } /** @test **/ public function it_can_set_the_message_recipient_from_a_method() { - $this->message->to("1234567890"); - $this->assertEquals($this->message->to,"1234567890"); + $this->message->to('1234567890'); + $this->assertEquals($this->message->to, '1234567890'); } /** @test **/ public function it_can_set_the_message_content_from_a_method() { - $this->message->content("Hello zing"); - $this->assertEquals($this->message->content,"Hello zing"); + $this->message->content('Hello zing'); + $this->assertEquals($this->message->content, 'Hello zing'); } /** @test **/ public function it_can_request_for_a_delivery_report() { $this->message->registeredDelivery(); - $this->assertEquals($this->message->registeredDelivery,"true"); + $this->assertEquals($this->message->registeredDelivery, 'true'); } /** @test **/ public function it_can_add_a_client_reference_to_the_sms() { - $this->message->clientReference("12345"); - $this->assertEquals($this->message->clientReference,"12345"); + $this->message->clientReference('12345'); + $this->assertEquals($this->message->clientReference, '12345'); } /** @test **/ public function it_can_state_the_message_type() { $this->message->type(2); - $this->assertEquals($this->message->type,2); + $this->assertEquals($this->message->type, 2); } /** @test **/ public function it_can_add_user_defined_headers_to_the_message() { - $this->message->udh("48656c6c6f207a696e67"); - $this->assertEquals($this->message->udh,"48656c6c6f207a696e67"); + $this->message->udh('48656c6c6f207a696e67'); + $this->assertEquals($this->message->udh, '48656c6c6f207a696e67'); } /** @test **/ public function it_can_set_the_time_to_send_the_message() { - $this->message->time("2017-10-12 10:24:30"); - $this->assertEquals($this->message->time,"2017-10-12 10:24:30"); + $this->message->time('2017-10-12 10:24:30'); + $this->assertEquals($this->message->time, '2017-10-12 10:24:30'); } /** @test **/ public function it_can_send_the_message_as_a_flash_message() { $this->message->flashMessage(); - $this->assertEquals($this->message->flashMessage,"true"); + $this->assertEquals($this->message->flashMessage, 'true'); } } \ No newline at end of file