Skip to content

Commit

Permalink
PSR2 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey McCormick committed Apr 24, 2016
1 parent 35b72b1 commit 9a7fb71
Show file tree
Hide file tree
Showing 20 changed files with 328 additions and 458 deletions.
52 changes: 22 additions & 30 deletions src/SimpleSoftwareIO/SMS/DriverManager.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
<?php namespace SimpleSoftwareIO\SMS;
<?php

/**
* Simple-SMS
* Simple-SMS is a package made for Laravel to send/receive (polling/pushing) text messages.
*
* @link http://www.simplesoftware.io
* @author Maksim (Ellrion) Platonov <[email protected]>, <[email protected]>
*
*/
namespace SimpleSoftwareIO\SMS;

use GuzzleHttp\Client;
use Illuminate\Support\Manager;
use SimpleSoftwareIO\SMS\Drivers\CallFireSMS;
use SimpleSoftwareIO\SMS\Drivers\EmailSMS;
use SimpleSoftwareIO\SMS\Drivers\EZTextingSMS;
use SimpleSoftwareIO\SMS\Drivers\LabsMobileSMS;
use SimpleSoftwareIO\SMS\Drivers\MozeoSMS;
use SimpleSoftwareIO\SMS\Drivers\NexmoSMS;
use SimpleSoftwareIO\SMS\Drivers\MozeoSMS;
use SimpleSoftwareIO\SMS\Drivers\TwilioSMS;
use SimpleSoftwareIO\SMS\Drivers\ZenviaSMS;
use SimpleSoftwareIO\SMS\Drivers\CallFireSMS;
use SimpleSoftwareIO\SMS\Drivers\EZTextingSMS;
use SimpleSoftwareIO\SMS\Drivers\LabsMobileSMS;

class DriverManager extends Manager
{
Expand All @@ -35,24 +28,23 @@ public function getDefaultDriver()
/**
* Set the default sms driver name.
*
* @param string $name
* @return void
* @param string $name
*/
public function setDefaultDriver($name)
{
$this->app['config']['sms.driver'] = $name;
}

/**
* Create an instance of the callfire driver
* Create an instance of the callfire driver.
*
* @return CallFireSMS
*/
protected function createCallfireDriver()
{
$config = $this->app['config']->get('sms.callfire', []);

$provider = new CallFireSMS(new Client);
$provider = new CallFireSMS(new Client());

$provider->setUser($config['app_login']);
$provider->setPassword($config['app_password']);
Expand All @@ -61,7 +53,7 @@ protected function createCallfireDriver()
}

/**
* Creates an instance of the email driver
* Creates an instance of the email driver.
*
* @return EmailSMS
*/
Expand All @@ -73,19 +65,19 @@ protected function createEmailDriver()
}

/**
* Create an instance of the eztexting driver
* Create an instance of the eztexting driver.
*
* @return EZTextingSMS
*/
protected function createEztextingDriver()
{
$config = $this->app['config']->get('sms.eztexting', []);

$provider = new EZTextingSMS(new Client);
$provider = new EZTextingSMS(new Client());

$data = [
'User' => $config['username'],
'Password' => $config['password']
'Password' => $config['password'],
];
$provider->buildBody($data);

Expand All @@ -96,13 +88,13 @@ protected function createLabsMobileDriver()
{
$config = $this->app['config']->get('sms.labsmobile', []);

$provider = new LabsMobileSMS(new Client);
$provider = new LabsMobileSMS(new Client());

$auth = [
'client' => $config['client'],
'username' => $config['username'],
'password' => $config['password'],
'test' => $config['test']
'test' => $config['test'],
];

$provider->buildBody($auth);
Expand All @@ -111,15 +103,15 @@ protected function createLabsMobileDriver()
}

/**
* Create an instance of the mozeo driver
* Create an instance of the mozeo driver.
*
* @return MozeoSMS
*/
protected function createMozeoDriver()
{
$config = $this->app['config']->get('sms.mozeo', []);

$provider = new MozeoSMS(new Client);
$provider = new MozeoSMS(new Client());

$auth = [
'companykey' => $config['company_key'],
Expand All @@ -132,7 +124,7 @@ protected function createMozeoDriver()
}

/**
* Create an instance of the nexmo driver
* Create an instance of the nexmo driver.
*
* @return MozeoSMS
*/
Expand All @@ -141,7 +133,7 @@ protected function createNexmoDriver()
$config = $this->app['config']->get('sms.nexmo', []);

$provider = new NexmoSMS(
new Client,
new Client(),
$config['api_key'],
$config['api_secret']
);
Expand All @@ -150,7 +142,7 @@ protected function createNexmoDriver()
}

/**
* Create an instance of the Twillo driver
* Create an instance of the Twillo driver.
*
* @return TwilioSMS
*/
Expand All @@ -167,7 +159,7 @@ protected function createTwilioDriver()
}

/**
* Create an instance of the Zenvia driver
* Create an instance of the Zenvia driver.
*
* @return ZenviaSMS
*/
Expand All @@ -176,7 +168,7 @@ protected function createZenviaDriver()
$config = $this->app['config']->get('sms.zenvia', []);

$provider = new ZenviaSMS(
new Client,
new Client(),
$config['account_key'],
$config['passcode'],
$config['callbackOption']
Expand Down
34 changes: 16 additions & 18 deletions src/SimpleSoftwareIO/SMS/Drivers/AbstractSMS.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
<?php namespace SimpleSoftwareIO\SMS\Drivers;
<?php

/**
* Simple-SMS
* Simple-SMS is a package made for Laravel to send/receive (polling/pushing) text messages.
*
* @link http://www.simplesoftware.io
* @author SimpleSoftware [email protected]
*
*/
namespace SimpleSoftwareIO\SMS\Drivers;

use SimpleSoftwareIO\SMS\IncomingMessage;

Expand Down Expand Up @@ -48,22 +41,23 @@ protected function buildCall($url)
}

/**
* Builds a URL
* Builds a URL.
*
* @param array $segments
*
* @return string
*/
protected function buildUrl(Array $segments = [])
protected function buildUrl(array $segments = [])
{
//Get the base URL and add a ?
$url = $this->apiBase . '?';
$url = $this->apiBase.'?';

if (isset($this->apiEnding)) {
$segments = array_merge($segments, $this->apiEnding);
}

foreach ($segments as $key => $value) {
$url = $url . "$key=$value&";
$url = $url."$key=$value&";
}

//Remove the final &
Expand All @@ -76,7 +70,7 @@ protected function buildUrl(Array $segments = [])
* Builds the body part of the request and adds it to the body array.
*
* @param array|string $values Provides the data to be merged into the array. If a string, the key must be provided.
* @param null $key Holds the key in which a string will be merged into the array.
* @param null $key Holds the key in which a string will be merged into the array.
*/
public function buildBody($values, $key = null)
{
Expand All @@ -101,7 +95,6 @@ protected function getBody()
* Sets the username for auth.
*
* @param $username
* @return void.
*/
public function setUser($username)
{
Expand All @@ -112,7 +105,6 @@ public function setUser($username)
* Sets the password for auth.
*
* @param $password
* @return void
*/
public function setPassword($password)
{
Expand All @@ -129,21 +121,23 @@ protected function getAuth()
if (isset($this->auth['username']) && isset($this->auth['password'])) {
return [$this->auth['username'], $this->auth['password']];
}
return null;

return;
}

/**
* Creates and sends a POST request to the requested URL.
*
* @return mixed
*
* @throws \Exception
*/
protected function postRequest()
{
$response = $this->client->post($this->buildUrl(),
[
'auth' => $this->getAuth(),
'form_params' => $this->getBody()
'form_params' => $this->getBody(),
]);

if ($response->getStatusCode() != 201 && $response->getStatusCode() != 200) {
Expand All @@ -157,6 +151,7 @@ protected function postRequest()
* Creates and sends a GET request to the requested URL.
*
* @return mixed
*
* @throws \Exception
*/
protected function getRequest()
Expand All @@ -176,6 +171,7 @@ protected function getRequest()
* Creates many IncomingMessage objects.
*
* @param $rawMessages
*
* @return array
*/
protected function makeMessages($rawMessages)
Expand All @@ -192,6 +188,7 @@ protected function makeMessages($rawMessages)
* Creates a single IncomingMessage object.
*
* @param $rawMessage
*
* @return mixed
*/
protected function makeMessage($rawMessage)
Expand All @@ -203,6 +200,7 @@ protected function makeMessage($rawMessage)
* Creates many IncomingMessage objects and sets all of the properties.
*
* @param $rawMessage
*
* @return mixed
*/
abstract protected function processReceive($rawMessage);
Expand Down
Loading

0 comments on commit 9a7fb71

Please sign in to comment.