Skip to content

Commit f657e19

Browse files
committed
Merge pull request parse-community#176 from juliangut/master
PSR2 possible compliance
2 parents 1c22f86 + ebecec0 commit f657e19

8 files changed

+73
-50
lines changed

src/Parse/ParseClient.php

+11-6
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public static function _encode($value, $allowParseObjects)
160160
}
161161

162162
if (!is_scalar($value) && $value !== null) {
163-
throw new \Exception('Invalid type encountered.');
163+
throw new Exception('Invalid type encountered.');
164164
}
165165

166166
return $value;
@@ -264,8 +264,12 @@ public static function _encodeArray($value, $allowParseObjects)
264264
*
265265
* @return mixed Result from Parse API Call.
266266
*/
267-
public static function _request($method, $relativeUrl, $sessionToken = null,
268-
$data = null, $useMasterKey = false
267+
public static function _request(
268+
$method,
269+
$relativeUrl,
270+
$sessionToken = null,
271+
$data = null,
272+
$useMasterKey = false
269273
) {
270274
if ($data === '[]') {
271275
$data = '{}';
@@ -464,7 +468,7 @@ public static function enableRevocableSessions()
464468

465469
/**
466470
* Sets number of seconds to wait while trying to connect. Use 0 to wait indefinitely, null to default behaviour.
467-
*
471+
*
468472
* @param int|null $connectionTimeout
469473
*/
470474
public static function setConnectionTimeout($connectionTimeout)
@@ -473,8 +477,9 @@ public static function setConnectionTimeout($connectionTimeout)
473477
}
474478

475479
/**
476-
* Sets maximum number of seconds of request/response operation. Use 0 to wait indefinitely, null to default behaviour.
477-
*
480+
* Sets maximum number of seconds of request/response operation.
481+
* Use 0 to wait indefinitely, null to default behaviour.
482+
*
478483
* @param int|null $timeout
479484
*/
480485
public static function setTimeout($timeout)

src/Parse/ParseException.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ class ParseException extends Exception
1818
* @param int $code Error code.
1919
* @param \Exception $previous Previous Exception.
2020
*/
21-
public function __construct($message, $code = 0,
22-
\Exception $previous = null
23-
) {
21+
public function __construct($message, $code = 0, Exception $previous = null)
22+
{
2423
parent::__construct($message, $code, $previous);
2524
}
2625
}

src/Parse/ParseObject.php

+40-29
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,8 @@ class ParseObject implements Encodable
101101
*
102102
* @throws Exception
103103
*/
104-
public function __construct($className = null, $objectId = null,
105-
$isPointer = false
106-
) {
104+
public function __construct($className = null, $objectId = null, $isPointer = false)
105+
{
107106
if (empty(self::$registeredSubclasses)) {
108107
throw new Exception(
109108
'You must initialize the ParseClient using ParseClient::initialize '.
@@ -266,7 +265,9 @@ private function hasDirtyChildren()
266265
{
267266
$result = false;
268267
self::traverse(
269-
true, $this->estimatedData, function ($object) use (&$result) {
268+
true,
269+
$this->estimatedData,
270+
function ($object) use (&$result) {
270271
if ($object instanceof ParseObject) {
271272
if ($object->isDirty()) {
272273
$result = true;
@@ -474,9 +475,8 @@ public function getUpdatedAt()
474475
*
475476
* @return object
476477
*/
477-
public static function create($className, $objectId = null,
478-
$isPointer = false
479-
) {
478+
public static function create($className, $objectId = null, $isPointer = false)
479+
{
480480
if (isset(self::$registeredSubclasses[$className])) {
481481
return new self::$registeredSubclasses[$className](
482482
$className, $objectId, $isPointer
@@ -502,7 +502,9 @@ public function fetch($useMasterKey = false)
502502
$response = ParseClient::_request(
503503
'GET',
504504
'classes/'.$this->className.'/'.$this->objectId,
505-
$sessionToken, null, $useMasterKey
505+
$sessionToken,
506+
null,
507+
$useMasterKey
506508
);
507509
$this->_mergeAfterFetch($response);
508510

@@ -771,9 +773,7 @@ public static function destroyAll(array $objects, $useMasterKey = false)
771773
}
772774
}
773775
if (count($errors)) {
774-
throw new ParseAggregateException(
775-
'Errors during batch destroy.', $errors
776-
);
776+
throw new ParseAggregateException('Errors during batch destroy.', $errors);
777777
}
778778
}
779779

@@ -795,7 +795,9 @@ private static function destroyBatch(array $objects, $useMasterKey = false)
795795
$sessionToken = ParseUser::getCurrentUser()->getSessionToken();
796796
}
797797
$result = ParseClient::_request(
798-
'POST', 'batch', $sessionToken,
798+
'POST',
799+
'batch',
800+
$sessionToken,
799801
json_encode(['requests' => $data]),
800802
$useMasterKey
801803
);
@@ -1004,13 +1006,19 @@ private static function deepSave($target, $useMasterKey = false)
10041006
$req = $requests[0];
10051007
$result = ParseClient::_request(
10061008
$req['method'],
1007-
$req['path'], $sessionToken, json_encode($req['body']), $useMasterKey
1009+
$req['path'],
1010+
$sessionToken,
1011+
json_encode($req['body']),
1012+
$useMasterKey
10081013
);
10091014
$batch[0]->mergeAfterSave($result);
10101015
} else {
10111016
$result = ParseClient::_request(
1012-
'POST', 'batch', $sessionToken,
1013-
json_encode(['requests' => $requests]), $useMasterKey
1017+
'POST',
1018+
'batch',
1019+
$sessionToken,
1020+
json_encode(['requests' => $requests]),
1021+
$useMasterKey
10141022
);
10151023

10161024
$errorCollection = [];
@@ -1037,9 +1045,7 @@ private static function deepSave($target, $useMasterKey = false)
10371045
}
10381046
}
10391047
if (count($errorCollection)) {
1040-
throw new ParseAggregateException(
1041-
'Errors during batch save.', $errorCollection
1042-
);
1048+
throw new ParseAggregateException('Errors during batch save.', $errorCollection);
10431049
}
10441050
}
10451051
}
@@ -1052,11 +1058,12 @@ private static function deepSave($target, $useMasterKey = false)
10521058
* @param array &$unsavedChildren Array to populate with children.
10531059
* @param array &$unsavedFiles Array to populate with files.
10541060
*/
1055-
private static function findUnsavedChildren($object,
1056-
&$unsavedChildren, &$unsavedFiles
1057-
) {
1061+
private static function findUnsavedChildren($object, &$unsavedChildren, &$unsavedFiles)
1062+
{
10581063
static::traverse(
1059-
true, $object, function ($obj) use (
1064+
true,
1065+
$object,
1066+
function ($obj) use (
10601067
&$unsavedChildren,
10611068
&$unsavedFiles
10621069
) {
@@ -1084,17 +1091,19 @@ private static function findUnsavedChildren($object,
10841091
*
10851092
* @return mixed The result of calling mapFunction on the root object.
10861093
*/
1087-
private static function traverse($deep, &$object, $mapFunction,
1088-
$seen = []
1089-
) {
1094+
private static function traverse($deep, &$object, $mapFunction, $seen = [])
1095+
{
10901096
if ($object instanceof self) {
10911097
if (in_array($object, $seen, true)) {
10921098
return;
10931099
}
10941100
$seen[] = $object;
10951101
if ($deep) {
10961102
self::traverse(
1097-
$deep, $object->estimatedData, $mapFunction, $seen
1103+
$deep,
1104+
$object->estimatedData,
1105+
$mapFunction,
1106+
$seen
10981107
);
10991108
}
11001109

@@ -1136,7 +1145,9 @@ private static function canBeSerializedAsValue($object)
11361145
{
11371146
$result = true;
11381147
self::traverse(
1139-
false, $object, function ($obj) use (&$result) {
1148+
false,
1149+
$object,
1150+
function ($obj) use (&$result) {
11401151
// short circuit as soon as possible.
11411152
if ($result === false) {
11421153
return;
@@ -1200,7 +1211,7 @@ public function getRelation($key, $className = null)
12001211
public function _toPointer()
12011212
{
12021213
if (!$this->objectId) {
1203-
throw new \Exception("Can't serialize an unsaved Parse.Object");
1214+
throw new Exception("Can't serialize an unsaved Parse.Object");
12041215
}
12051216

12061217
return [
@@ -1256,7 +1267,7 @@ public static function registerSubclass()
12561267
get_called_class();
12571268
}
12581269
} else {
1259-
throw new \Exception(
1270+
throw new Exception(
12601271
'Cannot register a subclass that does not have a parseClassName'
12611272
);
12621273
}

src/Parse/ParsePush.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public static function send($data, $useMasterKey = false)
6161
}
6262
if (isset($data['expiration_time'])) {
6363
$data['expiration_time'] = ParseClient::_encode(
64-
$data['expiration_time'], false
64+
$data['expiration_time'],
65+
false
6566
)['iso'];
6667
}
6768

src/Parse/ParseQuery.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,13 @@ public function addDescending($key)
450450
if (is_array($key)) {
451451
$key = array_map(
452452
function ($element) {
453-
return '-'.$element;
454-
}, $key
453+
return '-' . $element;
454+
},
455+
$key
455456
);
456457
$this->orderBy = array_merge($this->orderBy, $key);
457458
} else {
458-
$this->orderBy[] = '-'.$key;
459+
$this->orderBy[] = '-' . $key;
459460
}
460461

461462
return $this;
@@ -547,7 +548,8 @@ public function withinKilometers($key, $point, $maxDistance)
547548
public function withinGeoBox($key, $southwest, $northeast)
548549
{
549550
$this->addCondition(
550-
$key, '$within',
551+
$key,
552+
'$within',
551553
['$box' => [$southwest, $northeast]]
552554
);
553555

@@ -681,7 +683,8 @@ public function matchesKeyInQuery($key, $queryKey, $query)
681683
$queryParam = $query->_getOptions();
682684
$queryParam['className'] = $query->className;
683685
$this->addCondition(
684-
$key, '$select',
686+
$key,
687+
'$select',
685688
['key' => $queryKey, 'query' => $queryParam]
686689
);
687690

@@ -705,7 +708,8 @@ public function doesNotMatchKeyInQuery($key, $queryKey, $query)
705708
$queryParam = $query->_getOptions();
706709
$queryParam['className'] = $query->className;
707710
$this->addCondition(
708-
$key, '$dontSelect',
711+
$key,
712+
'$dontSelect',
709713
['key' => $queryKey, 'query' => $queryParam]
710714
);
711715

src/Parse/ParseUser.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ public static function loginWithAnonymous()
198198
$uuid_parts = str_split(md5(mt_rand()), 4);
199199
$data = ['authData' => [
200200
'anonymous' => [
201-
'id' => '{$uuid_parts[0]}{$uuid_parts[1]}-{$uuid_parts[2]}-{$uuid_parts[3]}-{$uuid_parts[4]}-{$uuid_parts[5]}{$uuid_parts[6]}{$uuid_parts[7]}',
201+
'id' => '{$uuid_parts[0]}{$uuid_parts[1]}-{$uuid_parts[2]}-{$uuid_parts[3]}'
202+
. '-{$uuid_parts[4]}-{$uuid_parts[5]}{$uuid_parts[6]}{$uuid_parts[7]}',
202203
],
203204
]];
204205

@@ -247,8 +248,11 @@ public function linkWithFacebook($id, $access_token, $expiration_date = null, $u
247248
],
248249
]];
249250
$result = ParseClient::_request(
250-
'PUT', 'users/'.$this->getObjectId(),
251-
$this->getSessionToken(), json_encode($data), $useMasterKey
251+
'PUT',
252+
'users/' . $this->getObjectId(),
253+
$this->getSessionToken(),
254+
json_encode($data),
255+
$useMasterKey
252256
);
253257
$user = new self();
254258
$user->_mergeAfterFetch($result);

tests/Parse/ParseQueryTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ function ($i) use ($restaurantRatings, $restaurantLocations) {
801801
function ($i) use ($personHomeTown, $personName) {
802802
$person = ParseObject::create('Person');
803803
$person->set('hometown', $personHomeTown[$i]);
804-
$person->set('name', $personName[$i]);
804+
$person->set('name', $personName[$i]);
805805

806806
return $person;
807807
}

tests/bootstrap.php

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
/*
43
* Used by the PHPUnit Test Suite to load dependencies and configure the main
54
* application path.

0 commit comments

Comments
 (0)