Passed
Branch main (ec7022)
by Razi
10:41
created
phpunit.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@
 block discarded – undo
3 3
 include __DIR__.'/vendor/autoload.php';
4 4
 
5 5
 $capsule = new \Illuminate\Database\Capsule\Manager;
6
-$capsule->addConnection([ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => 'prfx_' ]);
6
+$capsule->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => 'prfx_']);
7 7
 $capsule->setEventDispatcher(new \Illuminate\Events\Dispatcher);
8 8
 $capsule->bootEloquent();
9 9
 $capsule->setAsGlobal();
Please login to merge, or discard this patch.
src/Traits/CascadedSoftDeletes.php 2 patches
Spacing   +16 added lines, -18 removed lines patch added patch discarded remove patch
@@ -24,16 +24,16 @@  discard block
 block discarded – undo
24 24
     protected static function bootCascadedSoftDeletes()
25 25
     {
26 26
 
27
-        static::deleted(function ($model) {
27
+        static::deleted(function($model) {
28 28
             $model->deleteCascadedSoftDeletes();
29 29
         });
30 30
 
31 31
         if (static::instanceUsesSoftDelete()) {
32
-            static::restoring(function ($model) {
32
+            static::restoring(function($model) {
33 33
                 static::$instanceDeletedAt = $model->{$model->getDeletedAtColumn()};
34 34
             });
35 35
 
36
-            static::restored(function ($model) {
36
+            static::restored(function($model) {
37 37
                 $model->restoreCascadedSoftDeleted();
38 38
             });
39 39
         }
@@ -44,17 +44,16 @@  discard block
 block discarded – undo
44 44
      */
45 45
     protected function deleteCascadedSoftDeletes() : void
46 46
     {
47
-        if($this->isHardDeleting())
47
+        if ($this->isHardDeleting())
48 48
             return;
49 49
 
50
-        if(config('cascaded-soft-deletes.queue_cascades_by_default') === true) {
50
+        if (config('cascaded-soft-deletes.queue_cascades_by_default') === true) {
51 51
             CascadeSoftDeletes::dispatch($this, 'delete', null)->onQueue(config('cascaded-soft-deletes.queue_name'));
52 52
         }
53 53
         else {
54 54
             // @codeCoverageIgnoreStart
55 55
             Str::startsWith(app()->version(), "7") ? 
56
-                CascadeSoftDeletes::dispatchNow($this, 'delete', null) : 
57
-                CascadeSoftDeletes::dispatchSync($this, 'delete', null); 
56
+                CascadeSoftDeletes::dispatchNow($this, 'delete', null) : CascadeSoftDeletes::dispatchSync($this, 'delete', null); 
58 57
             // @codeCoverageIgnoreEnd
59 58
         }
60 59
 
@@ -65,14 +64,13 @@  discard block
 block discarded – undo
65 64
      */
66 65
     protected function restoreCascadedSoftDeleted() : void
67 66
     {
68
-        if(config('cascaded-soft-deletes.queue_cascades_by_default') === true) {
67
+        if (config('cascaded-soft-deletes.queue_cascades_by_default') === true) {
69 68
             CascadeSoftDeletes::dispatch($this, 'restore', static::$instanceDeletedAt)->onQueue(config('cascaded-soft-deletes.queue_name'));
70 69
         }
71 70
         else {
72 71
             // @codeCoverageIgnoreStart
73 72
             Str::startsWith(app()->version(), "7") ? 
74
-                CascadeSoftDeletes::dispatchNow($this, 'restore', static::$instanceDeletedAt) :
75
-                CascadeSoftDeletes::dispatchSync($this, 'restore', static::$instanceDeletedAt);
73
+                CascadeSoftDeletes::dispatchNow($this, 'restore', static::$instanceDeletedAt) : CascadeSoftDeletes::dispatchSync($this, 'restore', static::$instanceDeletedAt);
76 74
             // @codeCoverageIgnoreEnd
77 75
         }
78 76
         // CascadeSoftDeletes::dispatch($this, 'restore', static::$instanceDeletedAt);
@@ -85,9 +83,9 @@  discard block
 block discarded – undo
85 83
      */
86 84
     public function cascadeSoftDeletes(string $action, ?\Carbon\Carbon $instanceDeletedAt = null) : void
87 85
     {
88
-        if(method_exists($this, 'getCascadedSoftDeletes')) {
86
+        if (method_exists($this, 'getCascadedSoftDeletes')) {
89 87
             $relations = collect($this->getCascadedSoftDeletes());
90
-        } else if(property_exists($this, 'cascadedSoftDeletes')) {
88
+        } else if (property_exists($this, 'cascadedSoftDeletes')) {
91 89
             $relations = collect($this->cascadedSoftDeletes);
92 90
         } else {
93 91
             throw new RuntimeException('neither getCascadedSoftDeletes function or cascaded_soft_deletes property exists!');
@@ -96,18 +94,18 @@  discard block
 block discarded – undo
96 94
         $relations->each(function($item, $key) use ($action, $instanceDeletedAt) {
97 95
 
98 96
             $relation = $key;
99
-            if(is_numeric($key))
97
+            if (is_numeric($key))
100 98
                 $relation = $item;
101 99
 
102
-            if(!is_callable($item) && !$this->relationUsesSoftDelete($relation))
100
+            if (!is_callable($item) && !$this->relationUsesSoftDelete($relation))
103 101
                 throw new LogicException('relationship '.$relation.' does not use SoftDeletes trait.');
104 102
 
105
-            if(is_callable($item))
103
+            if (is_callable($item))
106 104
                 $query = $item();
107 105
             else
108 106
                 $query = $this->{$relation}();
109 107
 
110
-            if($action == 'delete')
108
+            if ($action == 'delete')
111 109
                 $query->get()->each->delete();
112 110
             else
113 111
                 $query
@@ -137,7 +135,7 @@  discard block
 block discarded – undo
137 135
      */
138 136
     protected function isHardDeleting() : bool
139 137
     {
140
-        return ! $this->instanceUsesSoftDelete() || $this->forceDeleting;
138
+        return !$this->instanceUsesSoftDelete() || $this->forceDeleting;
141 139
     }
142 140
 
143 141
     /**
@@ -167,7 +165,7 @@  discard block
 block discarded – undo
167 165
     {
168 166
         static $softDeletes;
169 167
 
170
-        if(is_null($softDeletes))
168
+        if (is_null($softDeletes))
171 169
             $softDeletes = collect([]);
172 170
 
173 171
         return $softDeletes->get($relation, function() use($relation, $softDeletes) {
Please login to merge, or discard this patch.
Braces   +27 added lines, -23 removed lines patch added patch discarded remove patch
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
      */
45 45
     protected function deleteCascadedSoftDeletes() : void
46 46
     {
47
-        if($this->isHardDeleting())
48
-            return;
47
+        if($this->isHardDeleting()) {
48
+                    return;
49
+        }
49 50
 
50 51
         if(config('cascaded-soft-deletes.queue_cascades_by_default') === true) {
51 52
             CascadeSoftDeletes::dispatch($this, 'delete', null)->onQueue(config('cascaded-soft-deletes.queue_name'));
52
-        }
53
-        else {
53
+        } else {
54 54
             // @codeCoverageIgnoreStart
55 55
             Str::startsWith(app()->version(), "7") ? 
56 56
                 CascadeSoftDeletes::dispatchNow($this, 'delete', null) : 
@@ -67,8 +67,7 @@  discard block
 block discarded – undo
67 67
     {
68 68
         if(config('cascaded-soft-deletes.queue_cascades_by_default') === true) {
69 69
             CascadeSoftDeletes::dispatch($this, 'restore', static::$instanceDeletedAt)->onQueue(config('cascaded-soft-deletes.queue_name'));
70
-        }
71
-        else {
70
+        } else {
72 71
             // @codeCoverageIgnoreStart
73 72
             Str::startsWith(app()->version(), "7") ? 
74 73
                 CascadeSoftDeletes::dispatchNow($this, 'restore', static::$instanceDeletedAt) :
@@ -96,26 +95,30 @@  discard block
 block discarded – undo
96 95
         $relations->each(function($item, $key) use ($action, $instanceDeletedAt) {
97 96
 
98 97
             $relation = $key;
99
-            if(is_numeric($key))
100
-                $relation = $item;
101
-
102
-            if(!is_callable($item) && !$this->relationUsesSoftDelete($relation))
103
-                throw new LogicException('relationship '.$relation.' does not use SoftDeletes trait.');
104
-
105
-            if(is_callable($item))
106
-                $query = $item();
107
-            else
108
-                $query = $this->{$relation}();
109
-
110
-            if($action == 'delete')
111
-                $query->get()->each->delete();
112
-            else
113
-                $query
98
+            if(is_numeric($key)) {
99
+                            $relation = $item;
100
+            }
101
+
102
+            if(!is_callable($item) && !$this->relationUsesSoftDelete($relation)) {
103
+                            throw new LogicException('relationship '.$relation.' does not use SoftDeletes trait.');
104
+            }
105
+
106
+            if(is_callable($item)) {
107
+                            $query = $item();
108
+            } else {
109
+                            $query = $this->{$relation}();
110
+            }
111
+
112
+            if($action == 'delete') {
113
+                            $query->get()->each->delete();
114
+            } else {
115
+                            $query
114 116
                     ->onlyTrashed()
115 117
                     ->where($this->getDeletedAtColumn(), '>=', $instanceDeletedAt->format('Y-m-d H:i:s.u'))
116 118
                     ->get()
117 119
                     ->each
118 120
                     ->restore();
121
+            }
119 122
 
120 123
             // else {
121 124
             //     $query = $query
@@ -167,8 +170,9 @@  discard block
 block discarded – undo
167 170
     {
168 171
         static $softDeletes;
169 172
 
170
-        if(is_null($softDeletes))
171
-            $softDeletes = collect([]);
173
+        if(is_null($softDeletes)) {
174
+                    $softDeletes = collect([]);
175
+        }
172 176
 
173 177
         return $softDeletes->get($relation, function() use($relation, $softDeletes) {
174 178
             $instance = new static;
Please login to merge, or discard this patch.