Skip to content

Commit 4d814ba

Browse files
author
Fosco Marotto
committed
Updated to full compliance with StyleCI
1 parent f7d7b0c commit 4d814ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+5919
-5887
lines changed

autoload.php

+13-15
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,44 @@
33
/**
44
* You only need this file if you are not using composer.
55
*/
6-
76
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
8-
throw new Exception('The Parse SDK requires PHP version 5.4 or higher.');
7+
throw new Exception('The Parse SDK requires PHP version 5.4 or higher.');
98
}
109

11-
/**
10+
/*
1211
* Register the autoloader for the Parse SDK
1312
* Based off the official PSR-4 autoloader example found here:
1413
* https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md
1514
*
1615
* @param string $class The fully-qualified class name.
1716
* @return void
1817
*/
19-
spl_autoload_register(function ($class)
20-
{
18+
spl_autoload_register(function ($class) {
2119
// Parse class prefix
2220
$prefix = 'Parse\\';
2321

2422
// base directory for the namespace prefix
25-
$base_dir = defined('PARSE_SDK_DIR') ? PARSE_SDK_DIR : __DIR__ . '/src/Parse/';
23+
$base_dir = defined('PARSE_SDK_DIR') ? PARSE_SDK_DIR : __DIR__.'/src/Parse/';
2624

2725
// does the class use the namespace prefix?
28-
$len = strlen( $prefix );
29-
if ( strncmp($prefix, $class, $len) !== 0 ) {
30-
// no, move to the next registered autoloader
26+
$len = strlen($prefix);
27+
if (strncmp($prefix, $class, $len) !== 0) {
28+
// no, move to the next registered autoloader
3129
return;
3230
}
3331

3432
// get the relative class name
35-
$relative_class = substr( $class, $len );
33+
$relative_class = substr($class, $len);
3634

3735
// replace the namespace prefix with the base directory, replace namespace
3836
// separators with directory separators in the relative class name, append
3937
// with .php
40-
$file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php';
41-
38+
$file = $base_dir.str_replace('\\', '/', $relative_class).'.php';
39+
4240
// echo $relative_class . '<br/>';
4341

4442
// if the file exists, require it
45-
if ( file_exists( $file ) ) {
46-
require $file;
43+
if (file_exists($file)) {
44+
require $file;
4745
}
48-
});
46+
});

src/Parse/Internal/AddOperation.php

+35-34
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
use Parse\ParseException;
77

88
/**
9-
* Class AddOperation - FieldOperation for adding object(s) to array fields
9+
* Class AddOperation - FieldOperation for adding object(s) to array fields.
1010
*
11-
* @package Parse
1211
* @author Fosco Marotto <[email protected]>
1312
*/
1413
class AddOperation implements FieldOperation
1514
{
16-
1715
/**
1816
* @var - Array with objects to add.
1917
*/
@@ -28,10 +26,10 @@ class AddOperation implements FieldOperation
2826
*/
2927
public function __construct($objects)
3028
{
31-
if (!is_array($objects)) {
32-
throw new ParseException("AddOperation requires an array.");
33-
}
34-
$this->objects = $objects;
29+
if (!is_array($objects)) {
30+
throw new ParseException("AddOperation requires an array.");
31+
}
32+
$this->objects = $objects;
3533
}
3634

3735
/**
@@ -41,7 +39,7 @@ public function __construct($objects)
4139
*/
4240
public function getValue()
4341
{
44-
return $this->objects;
42+
return $this->objects;
4543
}
4644

4745
/**
@@ -51,39 +49,42 @@ public function getValue()
5149
*/
5250
public function _encode()
5351
{
54-
return array('__op' => 'Add',
55-
'objects' => ParseClient::_encode($this->objects, true));
52+
return ['__op' => 'Add',
53+
'objects' => ParseClient::_encode($this->objects, true), ];
5654
}
5755

5856
/**
5957
* Takes a previous operation and returns a merged operation to replace it.
6058
*
6159
* @param FieldOperation $previous Previous operation.
6260
*
63-
* @return FieldOperation Merged operation.
6461
* @throws ParseException
62+
*
63+
* @return FieldOperation Merged operation.
6564
*/
6665
public function _mergeWithPrevious($previous)
6766
{
68-
if (!$previous) {
69-
return $this;
70-
}
71-
if ($previous instanceof DeleteOperation) {
72-
return new SetOperation($this->objects);
73-
}
74-
if ($previous instanceof SetOperation) {
75-
$oldList = $previous->getValue();
76-
return new SetOperation(
77-
array_merge((array)$oldList, (array)$this->objects)
67+
if (!$previous) {
68+
return $this;
69+
}
70+
if ($previous instanceof DeleteOperation) {
71+
return new SetOperation($this->objects);
72+
}
73+
if ($previous instanceof SetOperation) {
74+
$oldList = $previous->getValue();
75+
76+
return new SetOperation(
77+
array_merge((array) $oldList, (array) $this->objects)
7878
);
79-
}
80-
if ($previous instanceof AddOperation) {
81-
$oldList = $previous->getValue();
82-
return new SetOperation(
83-
array_merge((array)$oldList, (array)$this->objects)
79+
}
80+
if ($previous instanceof AddOperation) {
81+
$oldList = $previous->getValue();
82+
83+
return new SetOperation(
84+
array_merge((array) $oldList, (array) $this->objects)
8485
);
85-
}
86-
throw new ParseException(
86+
}
87+
throw new ParseException(
8788
'Operation is invalid after previous operation.'
8889
);
8990
}
@@ -99,10 +100,10 @@ public function _mergeWithPrevious($previous)
99100
*/
100101
public function _apply($oldValue, $obj, $key)
101102
{
102-
if (!$oldValue) {
103-
return $this->objects;
104-
}
105-
return array_merge((array)$oldValue, (array)$this->objects);
106-
}
103+
if (!$oldValue) {
104+
return $this->objects;
105+
}
107106

108-
}
107+
return array_merge((array) $oldValue, (array) $this->objects);
108+
}
109+
}

src/Parse/Internal/AddUniqueOperation.php

+61-59
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
/**
99
* Class AddUniqueOperation - Operation to add unique objects to an array key.
1010
*
11-
* @package Parse
1211
* @author Fosco Marotto <[email protected]>
1312
*/
1413
class AddUniqueOperation implements FieldOperation
1514
{
16-
1715
/**
1816
* @var - Array containing objects to add.
1917
*/
@@ -28,10 +26,10 @@ class AddUniqueOperation implements FieldOperation
2826
*/
2927
public function __construct($objects)
3028
{
31-
if (!is_array($objects)) {
32-
throw new ParseException("AddUniqueOperation requires an array.");
33-
}
34-
$this->objects = $objects;
29+
if (!is_array($objects)) {
30+
throw new ParseException("AddUniqueOperation requires an array.");
31+
}
32+
$this->objects = $objects;
3533
}
3634

3735
/**
@@ -41,7 +39,7 @@ public function __construct($objects)
4139
*/
4240
public function getValue()
4341
{
44-
return $this->objects;
42+
return $this->objects;
4543
}
4644

4745
/**
@@ -51,37 +49,40 @@ public function getValue()
5149
*/
5250
public function _encode()
5351
{
54-
return array('__op' => 'AddUnique',
55-
'objects' => ParseClient::_encode($this->objects, true));
52+
return ['__op' => 'AddUnique',
53+
'objects' => ParseClient::_encode($this->objects, true), ];
5654
}
5755

5856
/**
5957
* Merge this operation with the previous operation and return the result.
6058
*
6159
* @param FieldOperation $previous Previous Operation.
6260
*
63-
* @return FieldOperation Merged Operation.
6461
* @throws ParseException
62+
*
63+
* @return FieldOperation Merged Operation.
6564
*/
6665
public function _mergeWithPrevious($previous)
6766
{
68-
if (!$previous) {
69-
return $this;
70-
}
71-
if ($previous instanceof DeleteOperation) {
72-
return new SetOperation($this->objects);
73-
}
74-
if ($previous instanceof SetOperation) {
75-
$oldValue = $previous->getValue();
76-
$result = $this->_apply($oldValue, null, null);
77-
return new SetOperation($result);
78-
}
79-
if ($previous instanceof AddUniqueOperation) {
80-
$oldList = $previous->getValue();
81-
$result = $this->_apply($oldList, null, null);
82-
return new AddUniqueOperation($result);
83-
}
84-
throw new ParseException(
67+
if (!$previous) {
68+
return $this;
69+
}
70+
if ($previous instanceof DeleteOperation) {
71+
return new SetOperation($this->objects);
72+
}
73+
if ($previous instanceof SetOperation) {
74+
$oldValue = $previous->getValue();
75+
$result = $this->_apply($oldValue, null, null);
76+
77+
return new SetOperation($result);
78+
}
79+
if ($previous instanceof AddUniqueOperation) {
80+
$oldList = $previous->getValue();
81+
$result = $this->_apply($oldList, null, null);
82+
83+
return new AddUniqueOperation($result);
84+
}
85+
throw new ParseException(
8586
'Operation is invalid after previous operation.'
8687
);
8788
}
@@ -97,40 +98,41 @@ public function _mergeWithPrevious($previous)
9798
*/
9899
public function _apply($oldValue, $obj, $key)
99100
{
100-
if (!$oldValue) {
101-
return $this->objects;
102-
}
103-
if (!is_array($oldValue)) {
104-
$oldValue = (array)$oldValue;
105-
}
106-
foreach ($this->objects as $object) {
107-
if ($object instanceof ParseObject && $object->getObjectId()) {
108-
if (!$this->isParseObjectInArray($object, $oldValue)) {
109-
$oldValue[] = $object;
110-
}
111-
} else if (is_object($object)) {
112-
if (!in_array($object, $oldValue, true)) {
113-
$oldValue[] = $object;
114-
}
115-
} else {
116-
if (!in_array($object, $oldValue, true)) {
117-
$oldValue[] = $object;
118-
}
101+
if (!$oldValue) {
102+
return $this->objects;
119103
}
120-
}
121-
return $oldValue;
104+
if (!is_array($oldValue)) {
105+
$oldValue = (array) $oldValue;
106+
}
107+
foreach ($this->objects as $object) {
108+
if ($object instanceof ParseObject && $object->getObjectId()) {
109+
if (!$this->isParseObjectInArray($object, $oldValue)) {
110+
$oldValue[] = $object;
111+
}
112+
} elseif (is_object($object)) {
113+
if (!in_array($object, $oldValue, true)) {
114+
$oldValue[] = $object;
115+
}
116+
} else {
117+
if (!in_array($object, $oldValue, true)) {
118+
$oldValue[] = $object;
119+
}
120+
}
121+
}
122+
123+
return $oldValue;
122124
}
123125

124-
private function isParseObjectInArray($parseObject, $oldValue)
125-
{
126-
foreach ($oldValue as $object) {
127-
if ($object instanceof ParseObject && $object->getObjectId() != null) {
128-
if ($object->getObjectId() == $parseObject->getObjectId()) {
129-
return true;
126+
private function isParseObjectInArray($parseObject, $oldValue)
127+
{
128+
foreach ($oldValue as $object) {
129+
if ($object instanceof ParseObject && $object->getObjectId() != null) {
130+
if ($object->getObjectId() == $parseObject->getObjectId()) {
131+
return true;
132+
}
133+
}
130134
}
131-
}
132-
}
133-
return false;
134-
}
135135

136-
}
136+
return false;
137+
}
138+
}

src/Parse/Internal/DeleteOperation.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@
55
/**
66
* Class DeleteOperation - FieldOperation to remove a key from an object.
77
*
8-
* @package Parse
98
* @author Fosco Marotto <[email protected]>
109
*/
1110
class DeleteOperation implements FieldOperation
1211
{
13-
1412
/**
1513
* Returns an associative array encoding of the current operation.
1614
*
1715
* @return array Associative array encoding the operation.
1816
*/
1917
public function _encode()
2018
{
21-
return array('__op' => 'Delete');
19+
return ['__op' => 'Delete'];
2220
}
2321

2422
/**
@@ -32,7 +30,7 @@ public function _encode()
3230
*/
3331
public function _apply($oldValue, $object, $key)
3432
{
35-
return null;
33+
return;
3634
}
3735

3836
/**
@@ -44,7 +42,6 @@ public function _apply($oldValue, $object, $key)
4442
*/
4543
public function _mergeWithPrevious($previous)
4644
{
47-
return $this;
45+
return $this;
4846
}
49-
50-
}
47+
}

0 commit comments

Comments
 (0)