Completed
Push — master ( 6e5734...aebbed )
by Sherif
08:38
created
src/Modules/V1/Core/AbstractRepositories/AbstractRepository.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -63,14 +63,14 @@  discard block
 block discarded – undo
63 63
         /**
64 64
          * Construct the select conditions for the model.
65 65
          */
66
-        $model->where(function ($q) use ($query, $conditionColumns, $relations){
66
+        $model->where(function($q) use ($query, $conditionColumns, $relations){
67 67
 
68 68
             if (count($conditionColumns)) 
69 69
             {
70 70
                 /**
71 71
                  * Use the first element in the model columns to construct the first condition.
72 72
                  */
73
-                $q->where(\DB::raw('LOWER(' . array_shift($conditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%');
73
+                $q->where(\DB::raw('LOWER('.array_shift($conditionColumns).')'), 'LIKE', '%'.strtolower($query).'%');
74 74
             }
75 75
 
76 76
             /**
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
              */
79 79
             foreach ($conditionColumns as $column) 
80 80
             {
81
-                $q->orWhere(\DB::raw('LOWER(' . $column . ')'), 'LIKE', '%' . strtolower($query) . '%');
81
+                $q->orWhere(\DB::raw('LOWER('.$column.')'), 'LIKE', '%'.strtolower($query).'%');
82 82
             }
83 83
 
84 84
             /**
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
                     /**
100 100
                      * Construct the relation condition.
101 101
                      */
102
-                    $q->orWhereHas($relation, function ($subModel) use ($query, $relation){
102
+                    $q->orWhereHas($relation, function($subModel) use ($query, $relation){
103 103
 
104
-                        $subModel->where(function ($q) use ($query, $relation){
104
+                        $subModel->where(function($q) use ($query, $relation){
105 105
 
106 106
                             /**
107 107
                              * Get columns of the relation.
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
                                 /**
114 114
                                 * Use the first element in the relation model columns to construct the first condition.
115 115
                                  */
116
-                                $q->where(\DB::raw('LOWER(' . array_shift($subConditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%');
116
+                                $q->where(\DB::raw('LOWER('.array_shift($subConditionColumns).')'), 'LIKE', '%'.strtolower($query).'%');
117 117
                             }
118 118
 
119 119
                             /**
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
                              */
122 122
                             foreach ($subConditionColumns as $subConditionColumn)
123 123
                             {
124
-                                $q->orWhere(\DB::raw('LOWER(' . $subConditionColumn . ')'), 'LIKE', '%' . strtolower($query) . '%');
124
+                                $q->orWhere(\DB::raw('LOWER('.$subConditionColumn.')'), 'LIKE', '%'.strtolower($query).'%');
125 125
                             } 
126 126
                         });
127 127
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
         $modelClass = $this->model;
183 183
         $relations  = [];
184 184
 
185
-        \DB::transaction(function () use (&$model, &$relations, $data, $saveLog, $modelClass) {
185
+        \DB::transaction(function() use (&$model, &$relations, $data, $saveLog, $modelClass) {
186 186
             /**
187 187
              * If the id is present in the data then select the model for updating,
188 188
              * else create new model.
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
             $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
192 192
             if ( ! $model) 
193 193
             {
194
-                \ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']);
194
+                \ErrorHandler::notFound(class_basename($modelClass).' with id : '.$data['id']);
195 195
             }
196 196
 
197 197
             /**
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
                                  */
250 250
                                 if ( ! $relationModel) 
251 251
                                 {
252
-                                    \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']);
252
+                                    \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$val['id']);
253 253
                                 }
254 254
 
255 255
                                 /**
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
                                     /**
261 261
                                      * Prevent the sub relations or attributes not in the fillable.
262 262
                                      */
263
-                                    if (gettype($val) !== 'object' && gettype($val) !== 'array' &&  array_search($attr, $relationModel->getFillable(), true) !== false)
263
+                                    if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false)
264 264
                                     {
265 265
                                         $relationModel->$attr = $val;
266 266
                                     }
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
                                      */
291 291
                                     if ( ! $relationModel) 
292 292
                                     {
293
-                                        \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']);
293
+                                        \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$value['id']);
294 294
                                     }
295 295
 
296 296
                                     foreach ($value as $relationAttribute => $relationValue) 
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
         }
436 436
         else
437 437
         {
438
-            call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){
438
+            call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) use ($data, $saveLog){
439 439
                 $model->update($data);
440 440
                 $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
441 441
             });
@@ -454,11 +454,11 @@  discard block
 block discarded – undo
454 454
     {
455 455
         if ($attribute == 'id') 
456 456
         {
457
-            \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
457
+            \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) {
458 458
                 $model = $this->model->lockForUpdate()->find($value);
459 459
                 if ( ! $model) 
460 460
                 {
461
-                    \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value);
461
+                    \ErrorHandler::notFound(class_basename($this->model).' with id : '.$value);
462 462
                 }
463 463
                 
464 464
                 $model->delete();
@@ -467,8 +467,8 @@  discard block
 block discarded – undo
467 467
         }
468 468
         else
469 469
         {
470
-            \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
471
-                call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($saveLog){
470
+            \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) {
471
+                call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) use ($saveLog){
472 472
                     $model->delete();
473 473
                     $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
474 474
                 });
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
     {
506 506
         $conditions = $this->constructConditions($conditions, $this->model);
507 507
         $sort       = $desc ? 'desc' : 'asc';
508
-        return call_user_func_array("{$this->getModel()}::with",  array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
508
+        return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
509 509
     }
510 510
 
511 511
     /**
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
             $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
546 546
         }
547 547
 
548
-        return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);;
548
+        return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); ;
549 549
     }
550 550
 
551 551
     /**
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
 
561 561
         if ( ! $model) 
562 562
         {
563
-            \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $id);
563
+            \ErrorHandler::notFound(class_basename($this->model).' with id : '.$id);
564 564
         }
565 565
 
566 566
         $model->restore();
@@ -580,13 +580,13 @@  discard block
 block discarded – undo
580 580
             if ($key == 'and') 
581 581
             {
582 582
                 $conditions       = $this->constructConditions($value, $model);
583
-                $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']) . ' {op} ';
583
+                $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} ';
584 584
                 $conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
585 585
             }
586 586
             else if ($key == 'or')
587 587
             {
588 588
                 $conditions       = $this->constructConditions($value, $model);
589
-                $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']) . ' {op} ';
589
+                $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} ';
590 590
                 $conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
591 591
             }
592 592
             else
@@ -611,41 +611,41 @@  discard block
 block discarded – undo
611 611
                 
612 612
                 if (strtolower($operator) == 'between') 
613 613
                 {
614
-                    $conditionString  .= $key . ' >= ? and ';
614
+                    $conditionString  .= $key.' >= ? and ';
615 615
                     $conditionValues[] = $value1;
616 616
 
617
-                    $conditionString  .= $key . ' <= ? {op} ';
617
+                    $conditionString  .= $key.' <= ? {op} ';
618 618
                     $conditionValues[] = $value2;
619 619
                 }
620 620
                 elseif (strtolower($operator) == 'in') 
621 621
                 {
622 622
                     $conditionValues  = array_merge($conditionValues, $value);
623 623
                     $inBindingsString = rtrim(str_repeat('?,', count($value)), ',');
624
-                    $conditionString .= $key . ' in (' . rtrim($inBindingsString, ',') . ') {op} ';
624
+                    $conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} ';
625 625
                 }
626 626
                 elseif (strtolower($operator) == 'null') 
627 627
                 {
628
-                    $conditionString .= $key . ' is null {op} ';
628
+                    $conditionString .= $key.' is null {op} ';
629 629
                 }
630 630
                 elseif (strtolower($operator) == 'not null') 
631 631
                 {
632
-                    $conditionString .= $key . ' is not null {op} ';
632
+                    $conditionString .= $key.' is not null {op} ';
633 633
                 }
634 634
                 elseif (strtolower($operator) == 'has') 
635 635
                 {
636 636
                     $sql              = $model->withTrashed()->has($key)->toSql();
637 637
                     $conditions       = $this->constructConditions($value, $model->$key()->getRelated());
638
-                    $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')') . ' and ' . $conditions['conditionString'] . ') {op} ';
638
+                    $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')').' and '.$conditions['conditionString'].') {op} ';
639 639
                     $conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
640 640
                 }
641 641
                 else
642 642
                 {
643
-                    $conditionString  .= $key . ' ' . $operator . ' ? {op} ';
643
+                    $conditionString  .= $key.' '.$operator.' ? {op} ';
644 644
                     $conditionValues[] = $value;
645 645
                 }
646 646
             }
647 647
         }
648
-        $conditionString = '(' . rtrim($conditionString, '{op} ') . ')';
648
+        $conditionString = '('.rtrim($conditionString, '{op} ').')';
649 649
         return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
650 650
     }
651 651
 
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Repositories/UserRepository.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
         $user        = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id, $relations);
27 27
         foreach ($user->groups()->get() as $group)
28 28
         {
29
-            $group->permissions->each(function ($permission) use (&$permissions){
29
+            $group->permissions->each(function($permission) use (&$permissions){
30 30
                 $permissions[$permission->model][$permission->id] = $permission->name;
31 31
             });
32 32
         }
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      * @param  boolean $user
45 45
      * @return boolean
46 46
      */
47
-    public function can($nameOfPermission, $model, $user = false )
47
+    public function can($nameOfPermission, $model, $user = false)
48 48
     {      
49 49
         $user        = $user ?: \JWTAuth::parseToken()->authenticate();
50 50
         $permissions = [];
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
             \ErrorHandler::tokenExpired();
55 55
         }
56 56
 
57
-        $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){
57
+        $user->groups->pluck('permissions')->each(function($permission) use (&$permissions, $model){
58 58
             $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); 
59 59
         });
60 60
         
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
      * @param  integer $userId
69 69
      * @return boolean
70 70
      */
71
-    public function hasGroup($groupName, $userId = fa;se)
71
+    public function hasGroup($groupName, $userId = fa; se)
72 72
     {
73 73
         $userId = $userId ?: \JWTAuth::parseToken()->authenticate()->id;
74 74
         $groups = $this->find($userId)->groups;
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      */
85 85
     public function assignGroups($user_id, $group_ids)
86 86
     {
87
-        \DB::transaction(function () use ($user_id, $group_ids) {
87
+        \DB::transaction(function() use ($user_id, $group_ids) {
88 88
             $user = $this->find($user_id);
89 89
             $user->groups()->detach();
90 90
             $user->groups()->attach($group_ids);
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
         $url   = $this->config['resetLink'];
248 248
         $token = \Password::getRepository()->create($user);
249 249
         
250
-        \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) {
250
+        \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function($m) use ($user) {
251 251
             $m->to($user->email, $user->name)->subject('Your Password Reset Link');
252 252
         });
253 253
     }
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
     public function resetPassword($credentials)
262 262
     {
263 263
         $token    = false;
264
-        $response = \Password::reset($credentials, function ($user, $password) use (&$token) {
264
+        $response = \Password::reset($credentials, function($user, $password) use (&$token) {
265 265
             $user->password = $password;
266 266
             $user->save();
267 267
 
Please login to merge, or discard this patch.