Permalink
Browse files

Formatted code to PSR-2 standards

Used php-cs-fixer, all fixers except namespace filename fixer.
  • Loading branch information...
1 parent 3f6135e commit 3e4a6d4191eb18eab7844ec7c859f7e4c7383313 @maca134 committed Jul 5, 2012
View
@@ -37,5 +37,5 @@
'Twilio\\Twilio_Request_MakeCall' => __DIR__ . '/classes/twilio/request/makecall.php',
'Twilio\\Twilio_Request_Accounts' => __DIR__ . '/classes/twilio/request/accounts.php',
'Twilio\\Twilio_Request_Recordings' => __DIR__ . '/classes/twilio/request/recordings.php',
- 'Twilio\\Twilio_Request_Transcriptions' => __DIR__ . '/classes/twilio/request/transcriptions.php',
+ 'Twilio\\Twilio_Request_Transcriptions' => __DIR__ . '/classes/twilio/request/transcriptions.php',
));
View
@@ -14,14 +14,14 @@
namespace Twilio;
/**
- * Exception for Twilio
+ * Exception for Twilio
*/
class Twilio_Exception extends \FuelException {}
-class Twilio {
-
+class Twilio
+{
/**
- * @var array $allowed_requests Allowed Twilio requests
+ * @var array $allowed_requests Allowed Twilio requests
*/
private static $allowed_requests = array(
'SmsMessage',
@@ -33,25 +33,28 @@ class Twilio {
/**
* Prepares a request and returns the object
- *
- * @param string $type
- * @return Twilio_Request
- * @throws Twilio_Exception
+ *
+ * @param string $type
+ * @return Twilio_Request
+ * @throws Twilio_Exception
*/
- public static function request($type) {
+ public static function request($type)
+ {
$class = 'Twilio\Twilio_Request_' . $type;
if (!in_array($type, static::$allowed_requests) or !class_exists($class)) {
throw new Twilio_Exception($type . ' does not exist');
}
+
return call_user_func(array($class, 'forge'));
}
/**
* Gets a Twiml object
- *
+ *
* @return Twilio_Twiml
*/
- public static function twiml() {
+ public static function twiml()
+ {
return Twilio_Twiml::forge();
}
View
@@ -14,14 +14,14 @@
namespace Twilio;
/**
- * Exception for Twilio_Request
+ * Exception for Twilio_Request
*/
class Twilio_Request_Exception extends \FuelException {}
-abstract class Twilio_Request {
-
+abstract class Twilio_Request
+{
/**
- * @var string Request user agent
+ * @var string Request user agent
*/
private $useragent = 'fuel-twilio/0.1';
@@ -54,22 +54,24 @@ class Twilio_Request_Exception extends \FuelException {}
* @var string Stores Request URI
*/
protected $res = '';
-
+
/**
- * Returns a new Twilio_Request object
- *
+ * Returns a new Twilio_Request object
+ *
* @return Twilio_Request
*/
- public static function forge() {
+ public static function forge()
+ {
return new static();
}
/**
* Twilio_Request constructor
- *
- * @throws Twilio_Request_Exception
+ *
+ * @throws Twilio_Request_Exception
*/
- public function __construct() {
+ public function __construct()
+ {
$this->cainfo = realpath(dirname(__FILE__) . '/../' . $this->cainfo);
if (!in_array('curl', get_loaded_extensions())) {
@@ -90,17 +92,18 @@ public function __construct() {
\Config::load('twilio', true);
$this->_http->authenticate(\Config::get('twilio.account_sid'), \Config::get('twilio.auth_token'));
}
-
+
/**
* Sends the Twilio request
- *
- * @param string $res
- * @param string $body
- * @param string $method
- * @return stdClass An json_decoded object of the response
- * @throws Twilio_Request_Exception
+ *
+ * @param string $res
+ * @param string $body
+ * @param string $method
+ * @return stdClass An json_decoded object of the response
+ * @throws Twilio_Request_Exception
*/
- protected function send($res, $body = '', $method = 'POST') {
+ protected function send($res, $body = '', $method = 'POST')
+ {
$method = strtolower($method);
if (!in_array($method, array('post', 'get', 'put', 'delete'))) {
throw new Twilio_Request_Exception('Invalid http method');
@@ -110,16 +113,18 @@ protected function send($res, $body = '', $method = 'POST') {
$body = '';
}
$response = $this->_http->$method($res, array(), $body);
+
return json_decode($response[2]);
}
-
+
/**
* Creates and returns a http query string
- *
- * @param array $attr An associative array of attributes
- * @return string A http query string
+ *
+ * @param array $attr An associative array of attributes
+ * @return string A http query string
*/
- protected function create_post($attr = array()) {
+ protected function create_post($attr = array())
+ {
$post = array();
foreach ($this->defaults as $k => $v) {
@@ -129,6 +134,7 @@ protected function create_post($attr = array()) {
$post[$k] = $v;
}
}
+
return http_build_query($attr);
}
@@ -13,8 +13,8 @@
namespace Twilio;
-class Twilio_Request_Accounts extends Twilio_Request implements Twilio_Request_Base {
-
+class Twilio_Request_Accounts extends Twilio_Request implements Twilio_Request_Base
+{
/**
* @var array Stored default attributes
*/
@@ -27,13 +27,15 @@ class Twilio_Request_Accounts extends Twilio_Request implements Twilio_Request_B
/**
* Executes the request, returning the response
- *
- * @param array $attr An associative array of attributes for the request
- * @return type
+ *
+ * @param array $attr An associative array of attributes for the request
+ * @return type
*/
- public function create($attr = array()) {
+ public function create($attr = array())
+ {
$res = sprintf($this->res, \Config::get('twilio.account_sid'));
+
return $this->send($res, '', 'GET');
}
-}
+}
@@ -13,7 +13,7 @@
namespace Twilio;
-interface Twilio_Request_Base {
-
+interface Twilio_Request_Base
+{
public function create($attr);
-}
+}
@@ -13,8 +13,8 @@
namespace Twilio;
-class Twilio_Request_MakeCall extends Twilio_Request implements Twilio_Request_Base {
-
+class Twilio_Request_MakeCall extends Twilio_Request implements Twilio_Request_Base
+{
/**
* @var array Stored default attributes
*/
@@ -41,14 +41,16 @@ class Twilio_Request_MakeCall extends Twilio_Request implements Twilio_Request_B
/**
* Executes the request, returning the response
- *
- * @param array $attr An associative array of attributes for the request
- * @return stdClass An json_decoded object of the response
+ *
+ * @param array $attr An associative array of attributes for the request
+ * @return stdClass An json_decoded object of the response
*/
- public function create($attr = array()) {
+ public function create($attr = array())
+ {
$res = sprintf($this->res, \Config::get('twilio.account_sid'));
$body = $this->create_post($attr);
+
return $this->send($res, $body);
}
-}
+}
@@ -13,8 +13,8 @@
namespace Twilio;
-class Twilio_Request_Recordings extends Twilio_Request implements Twilio_Request_Base {
-
+class Twilio_Request_Recordings extends Twilio_Request implements Twilio_Request_Base
+{
/**
* @var array Stored default attributes
*/
@@ -33,11 +33,12 @@ class Twilio_Request_Recordings extends Twilio_Request implements Twilio_Request
/**
* Executes the request, returning the response
- *
- * @param array $attr An associative array of attributes for the request
- * @return stdClass An json_decoded object of the response
+ *
+ * @param array $attr An associative array of attributes for the request
+ * @return stdClass An json_decoded object of the response
*/
- public function create($attr = array()) {
+ public function create($attr = array())
+ {
$sid = (!empty($attr['Sid'])) ? '/' . $attr['Sid'] : '';
$accoundsid = \Config::get('twilio.account_sid');
@@ -58,18 +59,21 @@ public function create($attr = array()) {
} else {
$response->file = str_replace('.json', '.mp3', $response->uri);
}
+
return $response;
}
/**
* Executes the request, deleting the recording
- *
- * @param string $sid
- * @return stdClass An json_decoded object of the response
+ *
+ * @param string $sid
+ * @return stdClass An json_decoded object of the response
*/
- public function delete($sid) {
+ public function delete($sid)
+ {
$res = sprintf($this->res, \Config::get('twilio.account_sid'), '/' . $sid, '');
+
return $this->send($res, '', 'DELETE');
}
-}
+}
@@ -13,8 +13,8 @@
namespace Twilio;
-class Twilio_Request_SmsMessage extends Twilio_Request implements Twilio_Request_Base {
-
+class Twilio_Request_SmsMessage extends Twilio_Request implements Twilio_Request_Base
+{
/**
* @var array Stored default attributes
*/
@@ -34,19 +34,21 @@ class Twilio_Request_SmsMessage extends Twilio_Request implements Twilio_Request
/**
* Executes the request, returning the response
- *
- * @param array $attr An associative array of attributes for the request
- * @return stdClass An json_decoded object of the response
+ *
+ * @param array $attr An associative array of attributes for the request
+ * @return stdClass An json_decoded object of the response
*/
- public function create($attr = array()) {
+ public function create($attr = array())
+ {
$sid = (!empty($attr['Sid'])) ? '/' . $attr['Sid'] : '';
$res = sprintf($this->res, \Config::get('twilio.account_sid'), $sid);
unset($attr['Sid']);
$body = $this->create_post($attr);
+
return $this->send($res, $body);
}
-}
+}
@@ -15,16 +15,19 @@
class Twilio_Request_TinyHttpException extends \FuelException {}
-class Twilio_Request_TinyHttp {
+class Twilio_Request_TinyHttp
+{
private $user, $pass, $scheme, $host, $port, $debug, $curlopts;
- public function __construct($uri = '', $kwargs = array()) {
+ public function __construct($uri = '', $kwargs = array())
+ {
foreach (parse_url($uri) as $name => $value) $this->$name = $value;
$this->debug = isset($kwargs['debug']) ? !!$kwargs['debug'] : NULL;
$this->curlopts = isset($kwargs['curlopts']) ? $kwargs['curlopts'] : array();
}
- public function __call($name, $args) {
+ public function __call($name, $args)
+ {
list($res, $req_headers, $req_body) = $args + array(0, array(), '');
$opts = $this->curlopts + array(
@@ -89,6 +92,7 @@ public function __call($name, $args) {
}
curl_close($curl);
if (isset($buf) && is_resource($buf)) fclose($buf);
+
return array($status, $headers, $body);
} else throw new Twilio_TinyHttpException(curl_error($curl));
} else throw new Twilio_TinyHttpException(curl_error($curl));
@@ -100,8 +104,9 @@ public function __call($name, $args) {
}
}
- public function authenticate($user, $pass) {
+ public function authenticate($user, $pass)
+ {
$this->user = $user;
$this->pass = $pass;
}
-}
+}
Oops, something went wrong.

0 comments on commit 3e4a6d4

Please sign in to comment.