Skip to content

Commit

Permalink
fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Norris1z committed Oct 5, 2017
1 parent c9447e2 commit 5f1f5ba
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 70 deletions.
6 changes: 3 additions & 3 deletions src/Exceptions/CouldNotSendNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
4 changes: 2 additions & 2 deletions src/Exceptions/InvalidConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
14 changes: 5 additions & 9 deletions src/HubtelChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
40 changes: 20 additions & 20 deletions src/HubtelMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -90,7 +90,7 @@ public function to($to)
}

/**
* Set the message content
* Set the message content.
* @param string $content
* @return $this
*/
Expand All @@ -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
*/
Expand All @@ -122,7 +122,7 @@ public function clientReference($reference)
}

/**
* Set the message type
* Set the message type.
* @param int $type
* @return $this
*/
Expand All @@ -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
*/
Expand All @@ -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;
}
}
24 changes: 10 additions & 14 deletions src/SMSClients/HubtelSMSClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,40 +24,36 @@ 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()
{
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;
}
}

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;
Expand Down
7 changes: 4 additions & 3 deletions src/config/hubtel.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php
/**
* This file holds the configuration keys
* This file holds the configuration keys.
*/

return [
'account' => [
'key' => env('HUBTEL_API_KEY'),
'secret' => env('HUBTEL_API_SECRET')
]
'secret' => env('HUBTEL_API_SECRET'),
],

];
38 changes: 19 additions & 19 deletions tests/HubtelMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit 5f1f5ba

Please sign in to comment.