Passed
Push — master ( 7057c8...c1bd78 )
by Jesús
01:56
created
src/EloquentRepository.php 2 patches
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -22,12 +22,12 @@  discard block
 block discarded – undo
22 22
     /**
23 23
      * @param Model $model
24 24
      */
25
-    public function __construct( Model $model )
25
+    public function __construct(Model $model)
26 26
     {
27 27
         $this->model = $model;
28 28
         
29 29
         // A clean copy of the model is needed when the scope needs to be reset.
30
-        $reflex = new \ReflectionClass( $model );
30
+        $reflex = new \ReflectionClass($model);
31 31
         $this->modelClassName = $reflex->getName();
32 32
         
33 33
         $this->skipCriteria = FALSE;
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
         $this->eagerLoadRelations();
46 46
         $this->applyCriteria();
47 47
         
48
-        if ( !is_null( $value ) ) $this->model = $this->model->where( $field, $value );
48
+        if (!is_null($value)) $this->model = $this->model->where($field, $value);
49 49
         
50
-        $result = $this->model->first( $columns );
50
+        $result = $this->model->first($columns);
51 51
         
52 52
         $this->resetScope();
53 53
         
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
         $this->eagerLoadRelations();
66 66
         $this->applyCriteria();
67 67
         
68
-        if ( !is_null( $value ) && !is_null( $field ) ) $this->model = $this->model->where( $field, $value );
68
+        if (!is_null($value) && !is_null($field)) $this->model = $this->model->where($field, $value);
69 69
         
70
-        $result = $this->model->get( $columns );
70
+        $result = $this->model->get($columns);
71 71
         
72 72
         $this->resetScope();
73 73
         
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
     {
85 85
         $this->eagerLoadRelations();
86 86
         $this->applyCriteria();
87
-        $result = $this->model->whereIn( $field, $value )->get( $columns );
87
+        $result = $this->model->whereIn($field, $value)->get($columns);
88 88
         
89 89
         $this->resetScope();
90 90
         
@@ -95,10 +95,10 @@  discard block
 block discarded – undo
95 95
      * @param array $columns
96 96
      * @return \Illuminate\Database\Eloquent\Collection|static[]
97 97
      */
98
-    public function findAll( array $columns = ['*'] )
98
+    public function findAll(array $columns = ['*'])
99 99
     {
100 100
         $this->eagerLoadRelations();
101
-        $result = $this->model->all( $columns );
101
+        $result = $this->model->all($columns);
102 102
         
103 103
         $this->resetScope();
104 104
         
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
      * @param array|string $relations
110 110
      * @return $this
111 111
      */
112
-    public function with( $relations )
112
+    public function with($relations)
113 113
     {
114
-        if ( is_string( $relations ) ) $relations = func_get_args();
114
+        if (is_string($relations)) $relations = func_get_args();
115 115
         
116 116
         $this->with = $relations;
117 117
         
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
      * @param CriteriaInterface $criteria
124 124
      * @return $this
125 125
      */
126
-    public function addCriteria( CriteriaInterface $criteria)
126
+    public function addCriteria(CriteriaInterface $criteria)
127 127
     {
128 128
         $this->criteria[] = $criteria;
129 129
         
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
      * @param bool $status
136 136
      * @return $this
137 137
      */
138
-    public function skipCriteria( $status = TRUE )
138
+    public function skipCriteria($status = TRUE)
139 139
     {
140 140
         $this->skipCriteria = $status;
141 141
         return $this;
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
     {
152 152
         $this->eagerLoadRelations();
153 153
         $this->applyCriteria();
154
-        $result = $this->model->paginate( $perPage, $columns );
154
+        $result = $this->model->paginate($perPage, $columns);
155 155
         
156 156
         $this->resetScope();
157 157
         
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
      * @param int $currentPage
164 164
      * @return $this
165 165
      */
166
-    public function setCurrentPage( $currentPage )
166
+    public function setCurrentPage($currentPage)
167 167
     {
168
-        \Illuminate\Pagination\Paginator::currentPageResolver(function() use ( $currentPage )
168
+        \Illuminate\Pagination\Paginator::currentPageResolver(function() use ($currentPage)
169 169
         {
170 170
             return $currentPage;
171 171
         });
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
      */
181 181
     public function create(array $data)
182 182
     {
183
-        $cleanFields = $this->cleanUnfillableFields( $data );
183
+        $cleanFields = $this->cleanUnfillableFields($data);
184 184
         
185
-        $createdObject = $this->model->create( $cleanFields );
185
+        $createdObject = $this->model->create($cleanFields);
186 186
         
187 187
         $this->resetScope();
188 188
         
@@ -197,14 +197,14 @@  discard block
 block discarded – undo
197 197
      */
198 198
     public function updateBy(array $data, $value = NULL, $field = 'id')
199 199
     {
200
-        $cleanFields = $this->cleanUnfillableFields( $data );
200
+        $cleanFields = $this->cleanUnfillableFields($data);
201 201
         
202
-        if ( !is_null( $value ) )
202
+        if (!is_null($value))
203 203
         {
204 204
             // Single update.
205
-            $this->model->where( $field, $value)->update( $cleanFields );
205
+            $this->model->where($field, $value)->update($cleanFields);
206 206
             
207
-            foreach( $cleanFields as $F => $V ) $this->model->{$F} = $V;
207
+            foreach ($cleanFields as $F => $V) $this->model->{$F} = $V;
208 208
             
209 209
             $returnedVal = $this->model;
210 210
         } else
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
             // Mass update.
213 213
             $this->applyCriteria();
214 214
             
215
-            $returnedVal = $this->model->update( $cleanFields );
215
+            $returnedVal = $this->model->update($cleanFields);
216 216
         }
217 217
         
218 218
         $this->resetScope();
@@ -225,14 +225,14 @@  discard block
 block discarded – undo
225 225
      * @param string $field
226 226
      * @return bool
227 227
      */
228
-    public function delete( $value = null, $field = 'id' )
228
+    public function delete($value = null, $field = 'id')
229 229
     {
230 230
         $this->applyCriteria();
231 231
         
232
-        if ( !is_null( $value ) ) $result = $this->model->where( $field, $value )->delete();
232
+        if (!is_null($value)) $result = $this->model->where($field, $value)->delete();
233 233
         else
234 234
         {
235
-            if ( !empty( $this->criteria ) ) $result = $this->model->delete();
235
+            if (!empty($this->criteria)) $result = $this->model->delete();
236 236
             else $result = FALSE;
237 237
         }
238 238
         
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
     public function resetScope()
261 261
     {
262 262
         $this->criteria = [];
263
-        $this->skipCriteria( FALSE );
263
+        $this->skipCriteria(FALSE);
264 264
         $this->model = new $this->modelClassName();
265 265
         return $this;
266 266
     }
@@ -274,10 +274,10 @@  discard block
 block discarded – undo
274 274
     {
275 275
         $this->applyCriteria();
276 276
         
277
-        if ( !is_null( $value ) ) $result = $this->model->where( $field, $value )->forceDelete();
277
+        if (!is_null($value)) $result = $this->model->where($field, $value)->forceDelete();
278 278
         else
279 279
         {
280
-            if ( !empty( $this->criteria ) ) $result = $this->model->forceDelete();
280
+            if (!empty($this->criteria)) $result = $this->model->forceDelete();
281 281
             else $result = FALSE;
282 282
         }
283 283
         
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
      */
297 297
     protected function eagerLoadRelations()
298 298
     {
299
-        if ( is_array( $this->with ) ) $this->model->with( $this->with );
299
+        if (is_array($this->with)) $this->model->with($this->with);
300 300
     }
301 301
     
302 302
     
@@ -304,13 +304,13 @@  discard block
 block discarded – undo
304 304
      * @param array $data
305 305
      * @return array
306 306
      */
307
-    private function cleanUnfillableFields( array $data )
307
+    private function cleanUnfillableFields(array $data)
308 308
     {
309 309
         $fillableFields = $this->model->getFillable();
310 310
         
311
-        foreach( $data as $key => $value )
311
+        foreach ($data as $key => $value)
312 312
         {
313
-            if ( !in_array( $key, $fillableFields ) ) unset( $data[ $key ] );
313
+            if (!in_array($key, $fillableFields)) unset($data[$key]);
314 314
         }
315 315
         
316 316
         return $data;
@@ -321,11 +321,11 @@  discard block
 block discarded – undo
321 321
      */
322 322
     private function applyCriteria()
323 323
     {
324
-        if( !$this->skipCriteria )
324
+        if (!$this->skipCriteria)
325 325
         {
326
-            foreach( $this->criteria as $criteria )
326
+            foreach ($this->criteria as $criteria)
327 327
             {
328
-                if( $criteria instanceof CriteriaInterface ) $this->model = $criteria->apply( $this->model, $this );
328
+                if ($criteria instanceof CriteriaInterface) $this->model = $criteria->apply($this->model, $this);
329 329
             }
330 330
         }
331 331
         
Please login to merge, or discard this patch.
Braces   +37 added lines, -15 removed lines patch added patch discarded remove patch
@@ -45,7 +45,9 @@  discard block
 block discarded – undo
45 45
         $this->eagerLoadRelations();
46 46
         $this->applyCriteria();
47 47
         
48
-        if ( !is_null( $value ) ) $this->model = $this->model->where( $field, $value );
48
+        if ( !is_null( $value ) ) {
49
+            $this->model = $this->model->where( $field, $value );
50
+        }
49 51
         
50 52
         $result = $this->model->first( $columns );
51 53
         
@@ -65,7 +67,9 @@  discard block
 block discarded – undo
65 67
         $this->eagerLoadRelations();
66 68
         $this->applyCriteria();
67 69
         
68
-        if ( !is_null( $value ) && !is_null( $field ) ) $this->model = $this->model->where( $field, $value );
70
+        if ( !is_null( $value ) && !is_null( $field ) ) {
71
+            $this->model = $this->model->where( $field, $value );
72
+        }
69 73
         
70 74
         $result = $this->model->get( $columns );
71 75
         
@@ -111,7 +115,9 @@  discard block
 block discarded – undo
111 115
      */
112 116
     public function with( $relations )
113 117
     {
114
-        if ( is_string( $relations ) ) $relations = func_get_args();
118
+        if ( is_string( $relations ) ) {
119
+            $relations = func_get_args();
120
+        }
115 121
         
116 122
         $this->with = $relations;
117 123
         
@@ -204,7 +210,9 @@  discard block
 block discarded – undo
204 210
             // Single update.
205 211
             $this->model->where( $field, $value)->update( $cleanFields );
206 212
             
207
-            foreach( $cleanFields as $F => $V ) $this->model->{$F} = $V;
213
+            foreach( $cleanFields as $F => $V ) {
214
+                $this->model->{$F} = $V;
215
+            }
208 216
             
209 217
             $returnedVal = $this->model;
210 218
         } else
@@ -229,11 +237,15 @@  discard block
 block discarded – undo
229 237
     {
230 238
         $this->applyCriteria();
231 239
         
232
-        if ( !is_null( $value ) ) $result = $this->model->where( $field, $value )->delete();
233
-        else
240
+        if ( !is_null( $value ) ) {
241
+            $result = $this->model->where( $field, $value )->delete();
242
+        } else
234 243
         {
235
-            if ( !empty( $this->criteria ) ) $result = $this->model->delete();
236
-            else $result = FALSE;
244
+            if ( !empty( $this->criteria ) ) {
245
+                $result = $this->model->delete();
246
+            } else {
247
+                $result = FALSE;
248
+            }
237 249
         }
238 250
         
239 251
         $this->resetScope();
@@ -274,11 +286,15 @@  discard block
 block discarded – undo
274 286
     {
275 287
         $this->applyCriteria();
276 288
         
277
-        if ( !is_null( $value ) ) $result = $this->model->where( $field, $value )->forceDelete();
278
-        else
289
+        if ( !is_null( $value ) ) {
290
+            $result = $this->model->where( $field, $value )->forceDelete();
291
+        } else
279 292
         {
280
-            if ( !empty( $this->criteria ) ) $result = $this->model->forceDelete();
281
-            else $result = FALSE;
293
+            if ( !empty( $this->criteria ) ) {
294
+                $result = $this->model->forceDelete();
295
+            } else {
296
+                $result = FALSE;
297
+            }
282 298
         }
283 299
         
284 300
         $this->resetScope();
@@ -296,7 +312,9 @@  discard block
 block discarded – undo
296 312
      */
297 313
     protected function eagerLoadRelations()
298 314
     {
299
-        if ( is_array( $this->with ) ) $this->model->with( $this->with );
315
+        if ( is_array( $this->with ) ) {
316
+            $this->model->with( $this->with );
317
+        }
300 318
     }
301 319
     
302 320
     
@@ -310,7 +328,9 @@  discard block
 block discarded – undo
310 328
         
311 329
         foreach( $data as $key => $value )
312 330
         {
313
-            if ( !in_array( $key, $fillableFields ) ) unset( $data[ $key ] );
331
+            if ( !in_array( $key, $fillableFields ) ) {
332
+                unset( $data[ $key ] );
333
+            }
314 334
         }
315 335
         
316 336
         return $data;
@@ -325,7 +345,9 @@  discard block
 block discarded – undo
325 345
         {
326 346
             foreach( $this->criteria as $criteria )
327 347
             {
328
-                if( $criteria instanceof CriteriaInterface ) $this->model = $criteria->apply( $this->model, $this );
348
+                if( $criteria instanceof CriteriaInterface ) {
349
+                    $this->model = $criteria->apply( $this->model, $this );
350
+                }
329 351
             }
330 352
         }
331 353
         
Please login to merge, or discard this patch.