11<?php
22
3-
43namespace GearboxSolutions \EloquentFileMaker \Database \Eloquent ;
54
65use GearboxSolutions \EloquentFileMaker \Database \Eloquent \Concerns \FMHasRelationships ;
@@ -18,6 +17,7 @@ class FMEloquentBuilder extends Builder
1817
1918 /**
2019 * @return Collection
20+ *
2121 * @throws FileMakerDataApiException
2222 */
2323 public function get ($ columns = ['* ' ])
@@ -40,8 +40,8 @@ public function get($columns = ['*'])
4040 /**
4141 * Set the affected Eloquent model and instance ids.
4242 *
43- * @param FMModel $model
44- * @param int|array $ids
43+ * @param FMModel $model
44+ * @param int|array $ids
4545 * @return $this
4646 */
4747 public function setModel ($ model , $ ids = [])
@@ -55,7 +55,6 @@ public function setModel($model, $ids = [])
5555 return $ this ;
5656 }
5757
58-
5958 /**
6059 * Determine if any rows exist for the current query.
6160 * This actually runs the full query, so it doesn't save you any data, just an error capture
@@ -86,13 +85,13 @@ public function exists()
8685 */
8786 public function doesntExist ()
8887 {
89- return !$ this ->exists ();
88+ return ! $ this ->exists ();
9089 }
9190
9291 /**
9392 * Add a where clause on the primary key to the query.
9493 *
95- * @param mixed $id
94+ * @param mixed $id
9695 * @return $this
9796 */
9897 public function whereKeyNot ($ id )
@@ -108,7 +107,7 @@ public function whereKeyNot($id)
108107 }
109108
110109 // If this is our first where clause we can add the omit directly
111- if (count ($ this ->wheres ) === 0 ){
110+ if (count ($ this ->wheres ) === 0 ) {
112111 return $ this ->where ($ this ->model ->getKeyName (), '== ' , $ id )->omit ();
113112 }
114113
@@ -121,13 +120,14 @@ public function findByRecordId($recordId)
121120 $ response = $ this ->query ->findByRecordId ($ recordId );
122121 $ newRecord = $ response ['response ' ]['data ' ][0 ];
123122 $ newModel = $ this ->model ::createFromRecord ($ newRecord );
123+
124124 return $ newModel ;
125125 }
126126
127127 /**
128128 * Get a single column's value from the first result of a query.
129129 *
130- * @param string $column
130+ * @param string $column
131131 * @return mixed
132132 */
133133 public function value ($ column )
@@ -162,15 +162,15 @@ public function editRecord()
162162 $ fieldsToWrite = $ this ->model ->getAttributesForFileMakerWrite ();
163163
164164 $ modifiedPortals = null ;
165- foreach ($ fieldsToWrite as $ key => $ value ) {
165+ foreach ($ fieldsToWrite as $ key => $ value ) {
166166 // Check if the field is a portal (it should be an array if it is)
167167 if (is_array ($ value )) {
168168 $ modifiedPortals [$ key ] = $ this ->getOnlyModifiedPortalFields ($ fieldsToWrite [$ key ], $ this ->model ->getOriginal ($ key ));
169169 $ fieldsToWrite ->forget ($ key );
170170 }
171171 }
172172
173- if ($ fieldsToWrite ->count () > 0 || sizeof ($ modifiedPortals ?? []) > 0 ) {
173+ if ($ fieldsToWrite ->count () > 0 || count ($ modifiedPortals ?? []) > 0 ) {
174174 // we have some regular text fields to update
175175 // forward this request to a base query builder to execute the edit record request
176176 $ response = $ this ->query ->fieldData ($ fieldsToWrite ->toArray ())->portalData ($ modifiedPortals )->recordId ($ model ->getRecordId ())->editRecord ();
@@ -228,10 +228,10 @@ public function duplicate()
228228 /**
229229 * Paginate the given query.
230230 *
231- * @param int|null $perPage
232- * @param array $columns
233- * @param string $pageName
234- * @param int|null $page
231+ * @param int|null $perPage
232+ * @param array $columns
233+ * @param string $pageName
234+ * @param int|null $page
235235 * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
236236 *
237237 * @throws \InvalidArgumentException
@@ -260,21 +260,20 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page',
260260 *
261261 * @param $array1 array The modified portal data
262262 * @param $array2 array The model's original portal data
263- * @return array
264263 */
265264 protected function getOnlyModifiedPortalFields ($ array1 , $ array2 ): array
266265 {
267266 $ result = [];
268- foreach ($ array1 as $ key => $ val ) {
269- if ($ array2 [$ key ] != $ val ){
267+ foreach ($ array1 as $ key => $ val ) {
268+ if ($ array2 [$ key ] != $ val ) {
270269 // go recursive if we're comparing two arrays
271- if (is_array ($ val ) && is_array ($ array2 [$ key ])){
270+ if (is_array ($ val ) && is_array ($ array2 [$ key ])) {
272271 $ result [$ key ] = $ this ->getOnlyModifiedPortalFields ($ val , $ array2 [$ key ]);
273- } else {
272+ } else {
274273 // These are normal values, so compare directly
275274 $ result [$ key ] = $ val ;
276275 // at least one field is modified, so also set the recordID if it isn't set yet
277- if (! isset ($ result ['recordId ' ])){
276+ if (! isset ($ result ['recordId ' ])) {
278277 $ result ['recordId ' ] = $ array1 ['recordId ' ];
279278 }
280279 }
0 commit comments