THRIFT-2807 PHP CS Fix
This closes #252
Patch: Roger Thomas
diff --git a/lib/php/test/Test/Thrift/Fixtures.php b/lib/php/test/Test/Thrift/Fixtures.php
index 1b86f59..35fc0d9 100644
--- a/lib/php/test/Test/Thrift/Fixtures.php
+++ b/lib/php/test/Test/Thrift/Fixtures.php
@@ -52,12 +52,9 @@
self::$testArgs['testI32'] = pow( 2, 30 );
- if ( PHP_INT_SIZE == 8 )
- {
+ if (PHP_INT_SIZE == 8) {
self::$testArgs['testI64'] = pow( 2, 60 );
- }
- else
- {
+ } else {
self::$testArgs['testI64'] = "1152921504606847000";
}
diff --git a/lib/php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php b/lib/php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php
index 7e324f0..5c15bdf 100644
--- a/lib/php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php
+++ b/lib/php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php
@@ -21,9 +21,7 @@
namespace Test\Thrift\JsonSerialize;
use stdClass;
-use Test\Thrift\Fixtures;
use Thrift\ClassLoader\ThriftClassLoader;
-use Thrift\Serializer\TBinarySerializer;
require_once __DIR__.'/../../../../lib/Thrift/ClassLoader/ThriftClassLoader.php';
@@ -36,12 +34,14 @@
class JsonSerializeTest extends \PHPUnit_Framework_TestCase
{
- public function testEmptyStruct() {
+ public function testEmptyStruct()
+ {
$empty = new \ThriftTest\EmptyStruct(array('non_existing_key' => 'bar'));
- $this->assertEquals(new stdClass, json_decode(json_encode($empty)));
+ $this->assertEquals(new stdClass(), json_decode(json_encode($empty)));
}
- public function testStringsAndInts() {
+ public function testStringsAndInts()
+ {
$input = array(
'string_thing' => 'foo',
'i64_thing' => 1234567890,
@@ -49,13 +49,14 @@
$xtruct = new \ThriftTest\Xtruct($input);
// Xtruct's 'i32_thing' and 'byte_thing' fields should not be present here!
- $expected = new stdClass;
+ $expected = new stdClass();
$expected->string_thing = $input['string_thing'];
$expected->i64_thing = $input['i64_thing'];
$this->assertEquals($expected, json_decode(json_encode($xtruct)));
}
- public function testNestedStructs() {
+ public function testNestedStructs()
+ {
$xtruct2 = new \ThriftTest\Xtruct2(array(
'byte_thing' => 42,
'struct_thing' => new \ThriftTest\Xtruct(array(
@@ -63,29 +64,31 @@
)),
));
- $expected = new stdClass;
+ $expected = new stdClass();
$expected->byte_thing = $xtruct2->byte_thing;
- $expected->struct_thing = new stdClass;
+ $expected->struct_thing = new stdClass();
$expected->struct_thing->i32_thing = $xtruct2->struct_thing->i32_thing;
$this->assertEquals($expected, json_decode(json_encode($xtruct2)));
}
- public function testInsanity() {
+ public function testInsanity()
+ {
$xinput = array('string_thing' => 'foo');
$xtruct = new \ThriftTest\Xtruct($xinput);
$insanity = new \ThriftTest\Insanity(array(
'xtructs' => array($xtruct, $xtruct, $xtruct)
));
- $expected = new stdClass;
- $expected->xtructs = array((object)$xinput, (object)$xinput, (object)$xinput);
+ $expected = new stdClass();
+ $expected->xtructs = array((object) $xinput, (object) $xinput, (object) $xinput);
$this->assertEquals($expected, json_decode(json_encode($insanity)));
}
- public function testNestedLists() {
+ public function testNestedLists()
+ {
$bonk = new \ThriftTest\Bonk(array('message' => 'foo'));
$nested = new \ThriftTest\NestedListsBonk(array('bonk' => array(array(array($bonk)))));
- $expected = new stdClass;
- $expected->bonk = array(array(array((object)array('message' => 'foo'))));
+ $expected = new stdClass();
+ $expected->bonk = array(array(array((object) array('message' => 'foo'))));
$this->assertEquals($expected, json_decode(json_encode($nested)));
}
diff --git a/lib/php/test/Test/Thrift/Protocol/TestBinarySerializer.php b/lib/php/test/Test/Thrift/Protocol/TestBinarySerializer.php
index 65feadd..a983216 100644
--- a/lib/php/test/Test/Thrift/Protocol/TestBinarySerializer.php
+++ b/lib/php/test/Test/Thrift/Protocol/TestBinarySerializer.php
@@ -21,7 +21,7 @@
* @package thrift.test
*/
-namespace test\Thrift\Protocol;
+namespace Test\Thrift\Protocol;
use Thrift\ClassLoader\ThriftClassLoader;
use Thrift\Serializer\TBinarySerializer;
@@ -62,4 +62,3 @@
}
}
-
diff --git a/lib/php/test/Test/Thrift/Protocol/TestTJSONProtocol.php b/lib/php/test/Test/Thrift/Protocol/TestTJSONProtocol.php
index d5aa69c..7ba3441 100755
--- a/lib/php/test/Test/Thrift/Protocol/TestTJSONProtocol.php
+++ b/lib/php/test/Test/Thrift/Protocol/TestTJSONProtocol.php
@@ -28,7 +28,6 @@
use Thrift\Transport\TMemoryBuffer;
use Thrift\Protocol\TJSONProtocol;
-
define( 'BUFSIZ', 8192 ); //big enough to read biggest serialized Fixture arg.
require_once __DIR__.'/../../../../lib/Thrift/ClassLoader/ThriftClassLoader.php';
@@ -263,8 +262,8 @@
public function testVoid_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testVoid']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testVoid']
+ );
$args = new \ThriftTest\ThriftTest_testVoid_args();
$args->read( $this->protocol );
}
@@ -272,8 +271,8 @@
public function testString1_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testString1']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testString1']
+ );
$args = new \ThriftTest\ThriftTest_testString_args();
$args->read( $this->protocol );
@@ -286,8 +285,8 @@
public function testString2_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testString2']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testString2']
+ );
$args = new \ThriftTest\ThriftTest_testString_args();
$args->read( $this->protocol );
@@ -312,8 +311,8 @@
public function testDouble_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testDouble']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testDouble']
+ );
$args = new \ThriftTest\ThriftTest_testDouble_args();
$args->read( $this->protocol );
@@ -326,8 +325,8 @@
public function testByte_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testByte']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testByte']
+ );
$args = new \ThriftTest\ThriftTest_testByte_args();
$args->read( $this->protocol );
@@ -340,8 +339,8 @@
public function testI32_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testI32']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testI32']
+ );
$args = new \ThriftTest\ThriftTest_testI32_args();
$args->read( $this->protocol );
@@ -354,8 +353,8 @@
public function testI64_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testI64']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testI64']
+ );
$args = new \ThriftTest\ThriftTest_testI64_args();
$args->read( $this->protocol );
@@ -369,8 +368,8 @@
public function testStruct_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testStruct']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testStruct']
+ );
$args = new \ThriftTest\ThriftTest_testStruct_args();
$args->read( $this->protocol );
@@ -384,8 +383,8 @@
public function testNest_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testNest']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testNest']
+ );
$args = new \ThriftTest\ThriftTest_testNest_args();
$args->read( $this->protocol );
@@ -399,8 +398,8 @@
public function testMap_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testMap']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testMap']
+ );
$args = new \ThriftTest\ThriftTest_testMap_args();
$args->read( $this->protocol );
@@ -414,8 +413,8 @@
public function testStringMap_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testStringMap']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testStringMap']
+ );
$args = new \ThriftTest\ThriftTest_testStringMap_args();
$args->read( $this->protocol );
@@ -429,8 +428,8 @@
public function testSet_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testSet']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testSet']
+ );
$args = new \ThriftTest\ThriftTest_testSet_args();
$args->read( $this->protocol );
@@ -444,8 +443,8 @@
public function testList_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testList']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testList']
+ );
$args = new \ThriftTest\ThriftTest_testList_args();
$args->read( $this->protocol );
@@ -459,8 +458,8 @@
public function testEnum_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testEnum']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testEnum']
+ );
$args = new \ThriftTest\ThriftTest_testEnum_args();
$args->read( $this->protocol );
@@ -474,8 +473,8 @@
public function testTypedef_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testTypedef']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testTypedef']
+ );
$args = new \ThriftTest\ThriftTest_testTypedef_args();
$args->read( $this->protocol );
@@ -488,8 +487,8 @@
public function testMapMap_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testMapMap']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testMapMap']
+ );
$result = new \ThriftTest\ThriftTest_testMapMap_result();
$result->read( $this->protocol );
@@ -502,8 +501,8 @@
public function testInsanity_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testInsanity']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testInsanity']
+ );
$result = new \ThriftTest\ThriftTest_testInsanity_result();
$result->read( $this->protocol );
@@ -535,14 +534,11 @@
self::$testArgsJSON['testI32'] = '{"1":{"i32":1073741824}}';
- if ( PHP_INT_SIZE == 8 )
- {
+ if (PHP_INT_SIZE == 8) {
self::$testArgsJSON['testI64'] = '{"1":{"i64":'.pow( 2, 60 ).'}}';
self::$testArgsJSON['testStruct'] = '{"1":{"rec":{"1":{"str":"worked"},"4":{"i8":1},"9":{"i32":1073741824},"11":{"i64":'.pow( 2, 60 ).'}}}}';
self::$testArgsJSON['testNest'] = '{"1":{"rec":{"1":{"i8":1},"2":{"rec":{"1":{"str":"worked"},"4":{"i8":1},"9":{"i32":1073741824},"11":{"i64":'.pow( 2, 60 ).'}}},"3":{"i32":32768}}}}';
- }
- else
- {
+ } else {
self::$testArgsJSON['testI64'] = '{"1":{"i64":1152921504606847000}}';
self::$testArgsJSON['testStruct'] = '{"1":{"rec":{"1":{"str":"worked"},"4":{"i8":1},"9":{"i32":1073741824},"11":{"i64":1152921504606847000}}}}';
self::$testArgsJSON['testNest'] = '{"1":{"rec":{"1":{"i8":1},"2":{"rec":{"1":{"str":"worked"},"4":{"i8":1},"9":{"i32":1073741824},"11":{"i64":1152921504606847000}}},"3":{"i32":32768}}}}';
diff --git a/lib/php/test/Test/Thrift/TestValidators.php b/lib/php/test/Test/Thrift/TestValidators.php
index 4c92404..36cf000 100644
--- a/lib/php/test/Test/Thrift/TestValidators.php
+++ b/lib/php/test/Test/Thrift/TestValidators.php
@@ -38,11 +38,11 @@
// Would be nice to have PHPUnit here, but for now just hack it.
-set_exception_handler(function($e) {
+set_exception_handler(function ($e) {
my_assert(false, "Unexpected exception caught: " . $e->getMessage());
});
-set_error_handler(function($errno, $errmsg) {
+set_error_handler(function ($errno, $errmsg) {
my_assert(false, "Unexpected PHP error: " . $errmsg);
});
@@ -66,7 +66,7 @@
$bonk = new \ThriftTest\Bonk();
$transport = new TMemoryBuffer();
$protocol = new TBinaryProtocol($transport);
- assert_protocol_exception_thrown(function() use ($bonk, $protocol) { $bonk->write($protocol); },
+ assert_protocol_exception_thrown(function () use ($bonk, $protocol) { $bonk->write($protocol); },
'Bonk was able to write an empty object');
}
}
@@ -80,7 +80,7 @@
$structa = new \ThriftTest\StructA();
$transport = new TMemoryBuffer();
$protocol = new TBinaryProtocol($transport);
- assert_protocol_exception_thrown(function() use ($structa, $protocol) { $structa->write($protocol); },
+ assert_protocol_exception_thrown(function () use ($structa, $protocol) { $structa->write($protocol); },
'StructA was able to write an empty object');
}
{
@@ -100,27 +100,32 @@
assert_has_no_read_validator('TestValidators\TestService_test_result');
assert_has_no_write_validator('TestValidators\TestService_test_result');
-function assert_has_a_read_validator($class) {
+function assert_has_a_read_validator($class)
+{
my_assert(has_read_validator_method($class),
$class . ' class should have a read validator');
}
-function assert_has_no_read_validator($class) {
+function assert_has_no_read_validator($class)
+{
my_assert(!has_read_validator_method($class),
$class . ' class should not have a read validator');
}
-function assert_has_a_write_validator($class) {
+function assert_has_a_write_validator($class)
+{
my_assert(has_write_validator_method($class),
$class . ' class should have a write validator');
}
-function assert_has_no_write_validator($class) {
+function assert_has_no_write_validator($class)
+{
my_assert(!has_write_validator_method($class),
$class . ' class should not have a write validator');
}
-function assert_protocol_exception_thrown($callable, $message) {
+function assert_protocol_exception_thrown($callable, $message)
+{
try {
call_user_func($callable);
my_assert(false, $message);
@@ -128,17 +133,22 @@
}
}
-function has_write_validator_method($class) {
+function has_write_validator_method($class)
+{
$rc = new \ReflectionClass($class);
+
return $rc->hasMethod('_validateForWrite');
}
-function has_read_validator_method($class) {
+function has_read_validator_method($class)
+{
$rc = new \ReflectionClass($class);
+
return $rc->hasMethod('_validateForRead');
}
-function my_assert($something, $message) {
+function my_assert($something, $message)
+{
if (!$something) {
fwrite(STDERR, basename(__FILE__) . " FAILED: $message\n");
exit(1);