Completed
Push — master ( 8e6f6e...8506c8 )
by satoru
10s
created
src/Model/Behavior/SoftDeleteBehavior.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -17,27 +17,27 @@  discard block
 block discarded – undo
17 17
         'timestamp' => 'deleted_date'
18 18
     ];
19 19
 
20
-    public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary){
20
+    public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary) {
21 21
         $getOptions = $query->getOptions();
22 22
         if (
23
-            !array_key_exists('enableSoftDelete',$getOptions) ||
23
+            !array_key_exists('enableSoftDelete', $getOptions) ||
24 24
             $getOptions['enableSoftDelete'] == true
25
-        ){
25
+        ) {
26 26
             $modelName = $this->_table->alias();
27 27
             $booleanField = $this->config('boolean');
28 28
             $timestampField = $this->config('timestamp');
29
-            if ($booleanField !== false && $this->_table->hasField($booleanField)){
30
-                $query->where([$modelName . '.' . $booleanField => false]);
29
+            if ($booleanField !== false && $this->_table->hasField($booleanField)) {
30
+                $query->where([$modelName.'.'.$booleanField => false]);
31 31
             }
32
-            if ($booleanField === false && $timestampField !== false && $this->_table->hasField($timestampField)){
33
-                $query->where([$modelName . '.' . $timestampField .' IS' => null]);
32
+            if ($booleanField === false && $timestampField !== false && $this->_table->hasField($timestampField)) {
33
+                $query->where([$modelName.'.'.$timestampField.' IS' => null]);
34 34
             }
35 35
         }
36 36
     }
37 37
 
38
-    public function softDelete($deleteEntity){
38
+    public function softDelete($deleteEntity) {
39 39
         //データがぞんざいしない場合はエラー
40
-        if (!$this->dataExist($deleteEntity->{$this->_table->primaryKey()})){
40
+        if (!$this->dataExist($deleteEntity->{$this->_table->primaryKey()})) {
41 41
             return false;
42 42
         }
43 43
 
@@ -46,10 +46,10 @@  discard block
 block discarded – undo
46 46
         $now = Time::now();
47 47
 
48 48
         $delete_data = [];
49
-        if ($this->config('boolean') !== false){
49
+        if ($this->config('boolean') !== false) {
50 50
             $delete_data[$this->config('boolean')] = true;
51 51
         }
52
-        if ($this->config('timestamp') !== false){
52
+        if ($this->config('timestamp') !== false) {
53 53
             $delete_data[$this->config('timestamp')] = $now;
54 54
         }
55 55
         $saveEntity = $this->_table->patchEntity(
@@ -62,13 +62,13 @@  discard block
 block discarded – undo
62 62
 
63 63
         $behavior = $this;
64 64
 
65
-        $result = $this->_table->connection()->transactional(function () use ($behavior, $saveEntity, $id) {
65
+        $result = $this->_table->connection()->transactional(function() use ($behavior, $saveEntity, $id) {
66 66
             //削除データの保存に失敗
67
-            if (!$behavior->_table->save($saveEntity,['atomic' => false])){
67
+            if (!$behavior->_table->save($saveEntity, ['atomic' => false])) {
68 68
                 return false;
69 69
             }
70 70
             //最終的に存在していなければOK
71
-            if ($behavior->dataExist($id)){
71
+            if ($behavior->dataExist($id)) {
72 72
                 return false;
73 73
             }
74 74
             return true;
@@ -77,14 +77,14 @@  discard block
 block discarded – undo
77 77
         return $result;
78 78
     }
79 79
 
80
-    private function dataExist($id){
80
+    private function dataExist($id) {
81 81
         //数値などのチェック
82
-        if (!$id || !Validation::naturalNumber($id)){
82
+        if (!$id || !Validation::naturalNumber($id)) {
83 83
             return false;
84 84
         }
85 85
 
86 86
         $data = $this->_table->find()
87
-        ->where([$this->_table->alias() . '.' . $this->_table->primaryKey() => $id])
87
+        ->where([$this->_table->alias().'.'.$this->_table->primaryKey() => $id])
88 88
         ->first();
89 89
         ;
90 90
         return !empty($data);
Please login to merge, or discard this patch.