@@ -96,21 +96,21 @@ private function getFields(Context $context, bool $creating = false): array
9696 /**
9797 * Assert that the fields contained within a data object are valid.
9898 */
99- private function assertFieldsValid (Context $ context , array $ data , bool $ creating = false ): void
99+ private function assertFieldsValid (Context $ context , bool $ creating = false ): void
100100 {
101- $ this ->assertFieldsExist ($ context, $ data );
102- $ this ->assertFieldsWritable ($ context , $ data , $ creating );
101+ $ this ->assertFieldsExist ($ context );
102+ $ this ->assertFieldsWritable ($ context , $ creating );
103103 }
104104
105105 /**
106106 * Assert that the fields contained within a data object exist in the schema.
107107 */
108- private function assertFieldsExist (Context $ context, array $ data ): void
108+ private function assertFieldsExist (Context $ context ): void
109109 {
110110 $ fields = $ this ->getFields ($ context );
111111
112112 foreach (['attributes ' , 'relationships ' ] as $ location ) {
113- foreach ($ data [$ location ] as $ name => $ value ) {
113+ foreach ($ context -> data [$ location ] as $ name => $ value ) {
114114 if (!isset ($ fields [$ name ]) || $ location !== $ fields [$ name ]->location ()) {
115115 throw (new UnknownFieldException ($ name ))->source ([
116116 'pointer ' => '/data/ ' . implode ('/ ' , array_filter ([$ location , $ name ])),
@@ -125,13 +125,10 @@ private function assertFieldsExist(Context $context, array $data): void
125125 *
126126 * @throws ForbiddenException if a field is not writable.
127127 */
128- private function assertFieldsWritable (
129- Context $ context ,
130- array $ data ,
131- bool $ creating = false ,
132- ): void {
128+ private function assertFieldsWritable (Context $ context , bool $ creating = false ): void
129+ {
133130 foreach ($ this ->getFields ($ context , $ creating ) as $ field ) {
134- if (!has_value ($ data , $ field )) {
131+ if (!has_value ($ context -> data , $ field )) {
135132 continue ;
136133 }
137134
@@ -160,17 +157,17 @@ private function assertFieldWritable(
160157 /**
161158 *
162159 */
163- private function deserializeValues (Context $ context , array & $ data , bool $ creating = false ): void
160+ private function deserializeValues (Context $ context , bool $ creating = false ): void
164161 {
165162 foreach ($ this ->getFields ($ context , $ creating ) as $ field ) {
166- if (!has_value ($ data , $ field )) {
163+ if (!has_value ($ context -> data , $ field )) {
167164 continue ;
168165 }
169166
170- $ value = get_value ($ data , $ field );
167+ $ value = get_value ($ context -> data , $ field );
171168
172169 try {
173- set_value ($ data , $ field , $ field ->deserializeValue ($ value , $ context ));
170+ set_value ($ context -> data , $ field , $ field ->deserializeValue ($ value , $ context ));
174171 } catch (Sourceable $ e ) {
175172 throw $ e ->prependSource (['pointer ' => '/data ' . field_path ($ field )]);
176173 }
@@ -182,12 +179,12 @@ private function deserializeValues(Context $context, array &$data, bool $creatin
182179 *
183180 * @throws JsonApiErrorsException if any fields do not pass validation.
184181 */
185- private function assertDataValid (Context $ context , array $ data , bool $ validateAll ): void
182+ private function assertDataValid (Context $ context , bool $ validateAll ): void
186183 {
187184 $ errors = [];
188185
189186 foreach ($ this ->getFields ($ context , $ validateAll ) as $ field ) {
190- $ present = has_value ($ data , $ field );
187+ $ present = has_value ($ context -> data , $ field );
191188
192189 if (!$ present && (!$ field ->required || !$ validateAll )) {
193190 continue ;
@@ -200,7 +197,7 @@ private function assertDataValid(Context $context, array $data, bool $validateAl
200197 } else {
201198 array_push (
202199 $ errors ,
203- ...$ this ->validateField ($ context , $ field , get_value ($ data , $ field )),
200+ ...$ this ->validateField ($ context , $ field , get_value ($ context -> data , $ field )),
204201 );
205202 }
206203 }
@@ -232,14 +229,14 @@ private function validateField(Context $context, Field|Id $field, mixed $value):
232229 /**
233230 * Set field values from a data object to the model instance.
234231 */
235- private function setValues (Context $ context , array $ data , bool $ creating = false ): void
232+ private function setValues (Context $ context , bool $ creating = false ): void
236233 {
237234 foreach ($ this ->getFields ($ context , $ creating ) as $ field ) {
238- if (!has_value ($ data , $ field )) {
235+ if (!has_value ($ context -> data , $ field )) {
239236 continue ;
240237 }
241238
242- $ value = get_value ($ data , $ field );
239+ $ value = get_value ($ context -> data , $ field );
243240
244241 $ field ->setValue ($ context ->model , $ value , $ context );
245242 }
@@ -248,14 +245,14 @@ private function setValues(Context $context, array $data, bool $creating = false
248245 /**
249246 * Run any field save callbacks.
250247 */
251- private function saveFields (Context $ context , array $ data , bool $ creating = false ): void
248+ private function saveFields (Context $ context , bool $ creating = false ): void
252249 {
253250 foreach ($ this ->getFields ($ context , $ creating ) as $ field ) {
254- if (!has_value ($ data , $ field )) {
251+ if (!has_value ($ context -> data , $ field )) {
255252 continue ;
256253 }
257254
258- $ value = get_value ($ data , $ field );
255+ $ value = get_value ($ context -> data , $ field );
259256
260257 $ field ->saveValue ($ context ->model , $ value , $ context );
261258 }
0 commit comments