9
9
/**
10
10
* ParseRelationOperation - A class that is used to manage ParseRelation changes such as object add or remove.
11
11
*
12
- * @author Mohamed Madbouli <[email protected] >
12
+ * @author Mohamed Madbouli <[email protected] >
13
13
*/
14
14
class ParseRelationOperation implements FieldOperation
15
15
{
16
16
/**
17
- * @var string - The className of the target objects.
17
+ * The className of the target objects.
18
+ *
19
+ * @var string
18
20
*/
19
21
private $ targetClassName ;
22
+
20
23
/**
21
- * @var array - Array of objects to add to this relation.
24
+ * Array of objects to add to this relation.
25
+ *
26
+ * @var array
22
27
*/
23
28
private $ relationsToAdd = [];
29
+
24
30
/**
25
- * @var array - Array of objects to remove from this relation.
31
+ * Array of objects to remove from this relation.
32
+ *
33
+ * @var array
26
34
*/
27
35
private $ relationsToRemove = [];
28
36
@@ -126,10 +134,13 @@ public function _apply($oldValue, $object, $key)
126
134
return new ParseRelation ($ object , $ key , $ this ->targetClassName );
127
135
} elseif ($ oldValue instanceof ParseRelation) {
128
136
if ($ this ->targetClassName != null
129
- && $ oldValue ->getTargetClass () !== $ this ->targetClassName ) {
130
- throw new \Exception ('Related object object must be of class '
131
- .$ this ->targetClassName .', but ' .$ oldValue ->getTargetClass ()
132
- .' was passed in. ' );
137
+ && $ oldValue ->getTargetClass () !== $ this ->targetClassName
138
+ ) {
139
+ throw new \Exception (
140
+ 'Related object object must be of class '
141
+ .$ this ->targetClassName .', but ' .$ oldValue ->getTargetClass ()
142
+ .' was passed in. '
143
+ );
133
144
}
134
145
135
146
return $ oldValue ;
@@ -155,34 +166,50 @@ public function _mergeWithPrevious($previous)
155
166
}
156
167
if ($ previous instanceof ParseRelationOperation) {
157
168
if ($ previous ->targetClassName != null
158
- && $ previous ->targetClassName != $ this ->targetClassName
169
+ && $ previous ->targetClassName != $ this ->targetClassName
159
170
) {
160
- throw new \Exception ('Related object object must be of class '
161
- .$ this ->targetClassName .', but ' .$ previous ->targetClassName
162
- .' was passed in. ' );
171
+ throw new \Exception (
172
+ 'Related object object must be of class '
173
+ .$ this ->targetClassName .', but ' .$ previous ->targetClassName
174
+ .' was passed in. '
175
+ );
163
176
}
164
177
$ newRelationToAdd = self ::convertToOneDimensionalArray (
165
- $ this ->relationsToAdd );
178
+ $ this ->relationsToAdd
179
+ );
166
180
$ newRelationToRemove = self ::convertToOneDimensionalArray (
167
- $ this ->relationsToRemove );
181
+ $ this ->relationsToRemove
182
+ );
168
183
169
- $ previous ->addObjects ($ newRelationToAdd ,
170
- $ previous ->relationsToAdd );
171
- $ previous ->removeObjects ($ newRelationToAdd ,
172
- $ previous ->relationsToRemove );
184
+ $ previous ->addObjects (
185
+ $ newRelationToAdd ,
186
+ $ previous ->relationsToAdd
187
+ );
188
+ $ previous ->removeObjects (
189
+ $ newRelationToAdd ,
190
+ $ previous ->relationsToRemove
191
+ );
173
192
174
- $ previous ->removeObjects ($ newRelationToRemove ,
175
- $ previous ->relationsToAdd );
176
- $ previous ->addObjects ($ newRelationToRemove ,
177
- $ previous ->relationsToRemove );
193
+ $ previous ->removeObjects (
194
+ $ newRelationToRemove ,
195
+ $ previous ->relationsToAdd
196
+ );
197
+ $ previous ->addObjects (
198
+ $ newRelationToRemove ,
199
+ $ previous ->relationsToRemove
200
+ );
178
201
179
202
$ newRelationToAdd = self ::convertToOneDimensionalArray (
180
- $ previous ->relationsToAdd );
203
+ $ previous ->relationsToAdd
204
+ );
181
205
$ newRelationToRemove = self ::convertToOneDimensionalArray (
182
- $ previous ->relationsToRemove );
206
+ $ previous ->relationsToRemove
207
+ );
183
208
184
- return new ParseRelationOperation ($ newRelationToAdd ,
185
- $ newRelationToRemove );
209
+ return new ParseRelationOperation (
210
+ $ newRelationToAdd ,
211
+ $ newRelationToRemove
212
+ );
186
213
}
187
214
throw new \Exception ('Operation is invalid after previous operation. ' );
188
215
}
0 commit comments