THRIFT-2807 PHP CS Fix
This closes #252
Patch: Roger Thomas
diff --git a/lib/php/src/TStringUtils.php b/lib/php/src/TStringUtils.php
index 69672e8..894baf8 100644
--- a/lib/php/src/TStringUtils.php
+++ b/lib/php/src/TStringUtils.php
@@ -1,28 +1,33 @@
<?php
-interface TStringFunc {
+interface TStringFunc
+{
public function substr($str, $start, $length = null);
public function strlen($str);
}
class TStringFunc_Core
implements TStringFunc {
- public function substr($str, $start, $length = null) {
+ public function substr($str, $start, $length = null)
+ {
// specifying a null $length would return an empty string
- if($length === null) {
+ if ($length === null) {
return substr($str, $start);
}
+
return substr($str, $start, $length);
}
- public function strlen($str) {
+ public function strlen($str)
+ {
return strlen($str);
}
}
class TStringFunc_Mbstring
implements TStringFunc {
- public function substr($str, $start, $length = null) {
+ public function substr($str, $start, $length = null)
+ {
/**
* We need to set the charset parameter, which is the second
* optional parameter and the first optional parameter can't
@@ -30,19 +35,21 @@
* cause an empty string to be returned, so we need to
* actually calculate the proper length value.
*/
- if($length === null) {
+ if ($length === null) {
$length = $this->strlen($str) - $start;
}
return mb_substr($str, $start, $length, '8bit');
}
- public function strlen($str) {
+ public function strlen($str)
+ {
return mb_strlen($str, '8bit');
}
}
-class TStringFuncFactory {
+class TStringFuncFactory
+{
private static $_instance;
/**
@@ -51,22 +58,24 @@
*
* @return TStringFunc
*/
- public static function create() {
- if(!self::$_instance) {
+ public static function create()
+ {
+ if (!self::$_instance) {
self::_setInstance();
}
return self::$_instance;
}
- private static function _setInstance() {
+ private static function _setInstance()
+ {
/**
* Cannot use str* functions for byte counting because multibyte
* characters will be read a single bytes.
*
* See: http://us.php.net/manual/en/mbstring.overload.php
*/
- if(ini_get('mbstring.func_overload') & 2) {
+ if (ini_get('mbstring.func_overload') & 2) {
self::$_instance = new TStringFunc_Mbstring();
}
/**
diff --git a/lib/php/src/Thrift.php b/lib/php/src/Thrift.php
index c845395..4fe4392 100644
--- a/lib/php/src/Thrift.php
+++ b/lib/php/src/Thrift.php
@@ -20,11 +20,11 @@
* @package thrift
*/
-
/**
* Data types that can be sent via Thrift
*/
-class TType {
+class TType
+{
const STOP = 0;
const VOID = 1;
const BOOL = 2;
@@ -47,7 +47,8 @@
/**
* Message types for RPC
*/
-class TMessageType {
+class TMessageType
+{
const CALL = 1;
const REPLY = 2;
const EXCEPTION = 3;
@@ -67,8 +68,10 @@
* @param mixed $p1 Message (string) or type-spec (array)
* @param mixed $p2 Code (integer) or values (array)
*/
-class TException extends Exception {
- function __construct($p1=null, $p2=0) {
+class TException extends Exception
+{
+ public function __construct($p1=null, $p2=0)
+ {
if (is_array($p1) && is_array($p2)) {
$spec = $p1;
$vals = $p2;
@@ -91,7 +94,8 @@
TType::DOUBLE => 'Double',
TType::STRING => 'String');
- private function _readMap(&$var, $spec, $input) {
+ private function _readMap(&$var, $spec, $input)
+ {
$xfer = 0;
$ktype = $spec['ktype'];
$vtype = $spec['vtype'];
@@ -154,10 +158,12 @@
$var[$key] = $val;
}
$xfer += $input->readMapEnd();
+
return $xfer;
}
- private function _readList(&$var, $spec, $input, $set=false) {
+ private function _readList(&$var, $spec, $input, $set=false)
+ {
$xfer = 0;
$etype = $spec['etype'];
$eread = $vread = null;
@@ -207,10 +213,12 @@
} else {
$xfer += $input->readListEnd();
}
+
return $xfer;
}
- protected function _read($class, $spec, $input) {
+ protected function _read($class, $spec, $input)
+ {
$xfer = 0;
$fname = null;
$ftype = 0;
@@ -256,10 +264,12 @@
$xfer += $input->readFieldEnd();
}
$xfer += $input->readStructEnd();
+
return $xfer;
}
- private function _writeMap($var, $spec, $output) {
+ private function _writeMap($var, $spec, $output)
+ {
$xfer = 0;
$ktype = $spec['ktype'];
$vtype = $spec['vtype'];
@@ -314,10 +324,12 @@
}
}
$xfer += $output->writeMapEnd();
+
return $xfer;
}
- private function _writeList($var, $spec, $output, $set=false) {
+ private function _writeList($var, $spec, $output, $set=false)
+ {
$xfer = 0;
$etype = $spec['etype'];
$ewrite = null;
@@ -357,10 +369,12 @@
} else {
$xfer += $output->writeListEnd();
}
+
return $xfer;
}
- protected function _write($class, $spec, $output) {
+ protected function _write($class, $spec, $output)
+ {
$xfer = 0;
$xfer += $output->writeStructBegin($class);
foreach ($spec as $fid => $fspec) {
@@ -392,6 +406,7 @@
}
$xfer += $output->writeFieldStop();
$xfer += $output->writeStructEnd();
+
return $xfer;
}
@@ -404,8 +419,8 @@
* of PHP. Note that code is intentionally duplicated in here to avoid making
* function calls for every field or member of a container..
*/
-abstract class TBase {
-
+abstract class TBase
+{
static $tmethod = array(TType::BOOL => 'Bool',
TType::BYTE => 'Byte',
TType::I16 => 'I16',
@@ -414,11 +429,12 @@
TType::DOUBLE => 'Double',
TType::STRING => 'String');
- abstract function read($input);
+ abstract public function read($input);
- abstract function write($output);
+ abstract public function write($output);
- public function __construct($spec=null, $vals=null) {
+ public function __construct($spec=null, $vals=null)
+ {
if (is_array($spec) && is_array($vals)) {
foreach ($spec as $fid => $fspec) {
$var = $fspec['var'];
@@ -429,7 +445,8 @@
}
}
- private function _readMap(&$var, $spec, $input) {
+ private function _readMap(&$var, $spec, $input)
+ {
$xfer = 0;
$ktype = $spec['ktype'];
$vtype = $spec['vtype'];
@@ -492,10 +509,12 @@
$var[$key] = $val;
}
$xfer += $input->readMapEnd();
+
return $xfer;
}
- private function _readList(&$var, $spec, $input, $set=false) {
+ private function _readList(&$var, $spec, $input, $set=false)
+ {
$xfer = 0;
$etype = $spec['etype'];
$eread = $vread = null;
@@ -545,10 +564,12 @@
} else {
$xfer += $input->readListEnd();
}
+
return $xfer;
}
- protected function _read($class, $spec, $input) {
+ protected function _read($class, $spec, $input)
+ {
$xfer = 0;
$fname = null;
$ftype = 0;
@@ -594,10 +615,12 @@
$xfer += $input->readFieldEnd();
}
$xfer += $input->readStructEnd();
+
return $xfer;
}
- private function _writeMap($var, $spec, $output) {
+ private function _writeMap($var, $spec, $output)
+ {
$xfer = 0;
$ktype = $spec['ktype'];
$vtype = $spec['vtype'];
@@ -652,10 +675,12 @@
}
}
$xfer += $output->writeMapEnd();
+
return $xfer;
}
- private function _writeList($var, $spec, $output, $set=false) {
+ private function _writeList($var, $spec, $output, $set=false)
+ {
$xfer = 0;
$etype = $spec['etype'];
$ewrite = null;
@@ -695,10 +720,12 @@
} else {
$xfer += $output->writeListEnd();
}
+
return $xfer;
}
- protected function _write($class, $spec, $output) {
+ protected function _write($class, $spec, $output)
+ {
$xfer = 0;
$xfer += $output->writeStructBegin($class);
foreach ($spec as $fid => $fspec) {
@@ -730,11 +757,13 @@
}
$xfer += $output->writeFieldStop();
$xfer += $output->writeStructEnd();
+
return $xfer;
}
}
-class TApplicationException extends TException {
+class TApplicationException extends TException
+{
static $_TSPEC =
array(1 => array('var' => 'message',
'type' => TType::STRING),
@@ -750,15 +779,18 @@
const INTERNAL_ERROR = 6;
const PROTOCOL_ERROR = 7;
- function __construct($message=null, $code=0) {
+ public function __construct($message=null, $code=0)
+ {
parent::__construct($message, $code);
}
- public function read($output) {
+ public function read($output)
+ {
return $this->_read('TApplicationException', self::$_TSPEC, $output);
}
- public function write($output) {
+ public function write($output)
+ {
$xfer = 0;
$xfer += $output->writeStructBegin('TApplicationException');
if ($message = $this->getMessage()) {
@@ -773,6 +805,7 @@
}
$xfer += $output->writeFieldStop();
$xfer += $output->writeStructEnd();
+
return $xfer;
}
}
@@ -786,4 +819,3 @@
include_once $GLOBALS['THRIFT_ROOT'].'/protocol/TProtocol.php';
include_once $GLOBALS['THRIFT_ROOT'].'/transport/TTransport.php';
include_once $GLOBALS['THRIFT_ROOT'].'/TStringUtils.php';
-
diff --git a/lib/php/src/autoload.php b/lib/php/src/autoload.php
index 3a35545..85bd797 100644
--- a/lib/php/src/autoload.php
+++ b/lib/php/src/autoload.php
@@ -20,7 +20,6 @@
* @package thrift
*/
-
/**
* Include this file if you wish to use autoload with your PHP generated Thrift
* code. The generated code will *not* include any defined Thrift classes by
@@ -37,12 +36,13 @@
$GLOBALS['AUTOLOAD_HOOKS'] = array();
if (!function_exists('__autoload')) {
- function __autoload($class) {
+ function __autoload($class)
+ {
global $THRIFT_AUTOLOAD;
$classl = strtolower($class);
if (isset($THRIFT_AUTOLOAD[$classl])) {
include_once $GLOBALS['THRIFT_ROOT'].'/packages/'.$THRIFT_AUTOLOAD[$classl];
- } else if (!empty($GLOBALS['AUTOLOAD_HOOKS'])) {
+ } elseif (!empty($GLOBALS['AUTOLOAD_HOOKS'])) {
foreach ($GLOBALS['AUTOLOAD_HOOKS'] as $hook) {
$hook($class);
}