Skip to content

Commit

Permalink
Merge pull request parse-community#161 from yaman-jain/master
Browse files Browse the repository at this point in the history
using one convention
  • Loading branch information
gfosco committed Oct 12, 2015
2 parents faac43e + 1d6cf3d commit 534c693
Show file tree
Hide file tree
Showing 36 changed files with 1,016 additions and 1,051 deletions.
4 changes: 2 additions & 2 deletions src/Parse/Internal/AddOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AddOperation implements FieldOperation
public function __construct($objects)
{
if (!is_array($objects)) {
throw new ParseException("AddOperation requires an array.");
throw new ParseException('AddOperation requires an array.');
}
$this->objects = $objects;
}
Expand Down Expand Up @@ -79,7 +79,7 @@ public function _mergeWithPrevious($previous)
array_merge((array) $oldList, (array) $this->objects)
);
}
if ($previous instanceof AddOperation) {
if ($previous instanceof self) {
$oldList = $previous->getValue();

return new SetOperation(
Expand Down
6 changes: 3 additions & 3 deletions src/Parse/Internal/AddUniqueOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AddUniqueOperation implements FieldOperation
public function __construct($objects)
{
if (!is_array($objects)) {
throw new ParseException("AddUniqueOperation requires an array.");
throw new ParseException('AddUniqueOperation requires an array.');
}
$this->objects = $objects;
}
Expand Down Expand Up @@ -78,11 +78,11 @@ public function _mergeWithPrevious($previous)

return new SetOperation($result);
}
if ($previous instanceof AddUniqueOperation) {
if ($previous instanceof self) {
$oldList = $previous->getValue();
$result = $this->_apply($oldList, null, null);

return new AddUniqueOperation($result);
return new self($result);
}
throw new ParseException(
'Operation is invalid after previous operation.'
Expand Down
4 changes: 2 additions & 2 deletions src/Parse/Internal/IncrementOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public function _mergeWithPrevious($previous)
if ($previous instanceof SetOperation) {
return new SetOperation($previous->getValue() + $this->value);
}
if ($previous instanceof IncrementOperation) {
return new IncrementOperation(
if ($previous instanceof self) {
return new self(
$previous->getValue() + $this->value
);
}
Expand Down
19 changes: 10 additions & 9 deletions src/Parse/Internal/ParseRelationOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Parse\Internal;

use Exception;
use Parse\ParseClient;
use Parse\ParseObject;
use Parse\ParseRelation;
Expand All @@ -11,7 +12,7 @@
*
* @author Mohamed Madbouli <mohamedmadbouli@fb.com>
*/
class ParseRelationOperation implements FieldOperation
class ParseRelationOperation implements FieldOperation
{
/**
* The className of the target objects.
Expand Down Expand Up @@ -48,7 +49,7 @@ public function __construct($objectsToAdd, $objectsToRemove)
$this->addObjects($objectsToRemove, $this->relationsToRemove);
}
if ($this->targetClassName === null) {
throw new \Exception('Cannot create a ParseRelationOperation with no objects.');
throw new Exception('Cannot create a ParseRelationOperation with no objects.');
}
}

Expand All @@ -67,7 +68,7 @@ private function checkAndAssignClassName($objects)
$this->targetClassName = $object->getClassName();
}
if ($this->targetClassName != $object->getClassName()) {
throw new \Exception('All objects in a relation must be of the same class.');
throw new Exception('All objects in a relation must be of the same class.');
}
}
}
Expand Down Expand Up @@ -136,7 +137,7 @@ public function _apply($oldValue, $object, $key)
if ($this->targetClassName != null
&& $oldValue->getTargetClass() !== $this->targetClassName
) {
throw new \Exception(
throw new Exception(
'Related object object must be of class '
.$this->targetClassName.', but '.$oldValue->getTargetClass()
.' was passed in.'
Expand All @@ -145,7 +146,7 @@ public function _apply($oldValue, $object, $key)

return $oldValue;
} else {
throw new \Exception("Operation is invalid after previous operation.");
throw new Exception('Operation is invalid after previous operation.');
}
}

Expand All @@ -164,11 +165,11 @@ public function _mergeWithPrevious($previous)
if ($previous == null) {
return $this;
}
if ($previous instanceof ParseRelationOperation) {
if ($previous instanceof self) {
if ($previous->targetClassName != null
&& $previous->targetClassName != $this->targetClassName
) {
throw new \Exception(
throw new Exception(
'Related object object must be of class '
.$this->targetClassName.', but '.$previous->targetClassName
.' was passed in.'
Expand Down Expand Up @@ -206,12 +207,12 @@ public function _mergeWithPrevious($previous)
$previous->relationsToRemove
);

return new ParseRelationOperation(
return new self(
$newRelationToAdd,
$newRelationToRemove
);
}
throw new \Exception('Operation is invalid after previous operation.');
throw new Exception('Operation is invalid after previous operation.');
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Parse/Internal/RemoveOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RemoveOperation implements FieldOperation
public function __construct($objects)
{
if (!is_array($objects)) {
throw new ParseException("RemoveOperation requires an array.");
throw new ParseException('RemoveOperation requires an array.');
}
$this->objects = $objects;
}
Expand All @@ -53,8 +53,8 @@ public function getValue()
*/
public function _encode()
{
return ['__op' => 'Remove',
'objects' => ParseClient::_encode($this->objects, true), ];
return ['__op' => 'Remove',
'objects' => ParseClient::_encode($this->objects, true), ];
}

/**
Expand All @@ -79,10 +79,10 @@ public function _mergeWithPrevious($previous)
$this->_apply($previous->getValue(), $this->objects, null)
);
}
if ($previous instanceof RemoveOperation) {
if ($previous instanceof self) {
$oldList = $previous->getValue();

return new RemoveOperation(
return new self(
array_merge((array) $oldList, (array) $this->objects)
);
}
Expand Down
35 changes: 18 additions & 17 deletions src/Parse/ParseACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Parse;

use Exception;
use Parse\Internal\Encodable;

/**
Expand Down Expand Up @@ -57,7 +58,7 @@ class ParseACL implements Encodable
*/
public static function createACLWithUser($user)
{
$acl = new ParseACL();
$acl = new self();
$acl->setUserReadAccess($user, true);
$acl->setUserWriteAccess($user, true);

Expand All @@ -75,19 +76,19 @@ public static function createACLWithUser($user)
*/
public static function _createACLFromJSON($data)
{
$acl = new ParseACL();
$acl = new self();
foreach ($data as $id => $permissions) {
if (!is_string($id)) {
throw new \Exception('Tried to create an ACL with an invalid userId.');
throw new Exception('Tried to create an ACL with an invalid userId.');
}
foreach ($permissions as $accessType => $value) {
if ($accessType !== 'read' && $accessType !== 'write') {
throw new \Exception(
throw new Exception(
'Tried to create an ACL with an invalid permission type.'
);
}
if (!is_bool($value)) {
throw new \Exception(
throw new Exception(
'Tried to create an ACL with an invalid permission value.'
);
}
Expand Down Expand Up @@ -143,11 +144,11 @@ private function setAccess($accessType, $userId, $allowed)
$userId = $userId->getObjectId();
}
if ($userId instanceof ParseRole) {
$userId = "role:".$userId->getName();
$userId = 'role:'.$userId->getName();
}
if (!is_string($userId)) {
throw new ParseException(
"Invalid target for access control."
'Invalid target for access control.'
);
}
if (!isset($this->permissionsById[$userId])) {
Expand Down Expand Up @@ -197,7 +198,7 @@ private function getAccess($accessType, $userId)
public function setReadAccess($userId, $allowed)
{
if (!$userId) {
throw new \Exception("cannot setReadAccess for null userId");
throw new Exception('cannot setReadAccess for null userId');
}
$this->setAccess('read', $userId, $allowed);
}
Expand All @@ -217,7 +218,7 @@ public function setReadAccess($userId, $allowed)
public function getReadAccess($userId)
{
if (!$userId) {
throw new \Exception("cannot getReadAccess for null userId");
throw new Exception('cannot getReadAccess for null userId');
}

return $this->getAccess('read', $userId);
Expand All @@ -234,7 +235,7 @@ public function getReadAccess($userId)
public function setWriteAccess($userId, $allowed)
{
if (!$userId) {
throw new \Exception("cannot setWriteAccess for null userId");
throw new Exception('cannot setWriteAccess for null userId');
}
$this->setAccess('write', $userId, $allowed);
}
Expand All @@ -254,7 +255,7 @@ public function setWriteAccess($userId, $allowed)
public function getWriteAccess($userId)
{
if (!$userId) {
throw new \Exception("cannot getWriteAccess for null userId");
throw new Exception('cannot getWriteAccess for null userId');
}

return $this->getAccess('write', $userId);
Expand Down Expand Up @@ -311,7 +312,7 @@ public function getPublicWriteAccess()
public function setUserReadAccess($user, $allowed)
{
if (!$user->getObjectId()) {
throw new \Exception("cannot setReadAccess for a user with null id");
throw new Exception('cannot setReadAccess for a user with null id');
}
$this->setReadAccess($user->getObjectId(), $allowed);
}
Expand All @@ -331,7 +332,7 @@ public function setUserReadAccess($user, $allowed)
public function getUserReadAccess($user)
{
if (!$user->getObjectId()) {
throw new \Exception("cannot getReadAccess for a user with null id");
throw new Exception('cannot getReadAccess for a user with null id');
}

return $this->getReadAccess($user->getObjectId());
Expand All @@ -348,7 +349,7 @@ public function getUserReadAccess($user)
public function setUserWriteAccess($user, $allowed)
{
if (!$user->getObjectId()) {
throw new \Exception("cannot setWriteAccess for a user with null id");
throw new Exception('cannot setWriteAccess for a user with null id');
}
$this->setWriteAccess($user->getObjectId(), $allowed);
}
Expand All @@ -368,7 +369,7 @@ public function setUserWriteAccess($user, $allowed)
public function getUserWriteAccess($user)
{
if (!$user->getObjectId()) {
throw new \Exception("cannot getWriteAccess for a user with null id");
throw new Exception('cannot getWriteAccess for a user with null id');
}

return $this->getWriteAccess($user->getObjectId());
Expand Down Expand Up @@ -436,8 +437,8 @@ public function setRoleWriteAccessWithName($roleName, $allowed)
private static function validateRoleState($role)
{
if (!$role->getObjectId()) {
throw new \Exception(
"Roles must be saved to the server before they can be used in an ACL."
throw new Exception(
'Roles must be saved to the server before they can be used in an ACL.'
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Parse/ParseAnalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function track($name, $dimensions = [])

return ParseClient::_request(
'POST',
'events/' . $name,
'events/'.$name,
null,
static::_toSaveJSON($dimensions)
);
Expand Down
10 changes: 6 additions & 4 deletions src/Parse/ParseBytes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace Parse;

use Parse\Internal\Encodable;

/**
* ParseBytes - Representation of a Byte array for storage on a Parse Object.
*
* @author Fosco Marotto <fjm@fb.com>
*/
class ParseBytes implements Internal\Encodable
class ParseBytes implements Encodable
{
/**
* Byte array.
Expand All @@ -25,7 +27,7 @@ class ParseBytes implements Internal\Encodable
*/
public static function createFromByteArray(array $byteArray)
{
$bytes = new ParseBytes();
$bytes = new self();
$bytes->setByteArray($byteArray);

return $bytes;
Expand All @@ -40,7 +42,7 @@ public static function createFromByteArray(array $byteArray)
*/
public static function createFromBase64Data($base64Data)
{
$bytes = new ParseBytes();
$bytes = new self();
$bytes->setBase64Data($base64Data);

return $bytes;
Expand All @@ -64,7 +66,7 @@ private function setByteArray(array $byteArray)
*/
public function _encode()
{
$data = "";
$data = '';
foreach ($this->byteArray as $byte) {
$data .= chr($byte);
}
Expand Down
Loading

0 comments on commit 534c693

Please sign in to comment.