Completed
Push — master ( 65e241...68a338 )
by Francis
06:57
created
libraries/RefactorPayload.php 3 patches
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -5,104 +5,104 @@
 block discarded – undo
5 5
 
6 6
 class RefactorPayload
7 7
 {
8
-  protected $payload;
9
-  /**
10
-   * [__construct description]
11
-   * @date  2019-11-02
12
-   * @param array      $payload [description]
13
-   */
14
-  public function __construct($payload=[])
15
-  {
8
+    protected $payload;
9
+    /**
10
+     * [__construct description]
11
+     * @date  2019-11-02
12
+     * @param array      $payload [description]
13
+     */
14
+    public function __construct($payload=[])
15
+    {
16 16
     $this->payload = $payload;
17
-  }
18
-  /**
19
-   * [__set description]
20
-   * @date  2019-11-02
21
-   * @param string     $key   [description]
22
-   * @param [type]     $value [description]
23
-   */
24
-  public function __set(string $key, $value):void
25
-  {
17
+    }
18
+    /**
19
+     * [__set description]
20
+     * @date  2019-11-02
21
+     * @param string     $key   [description]
22
+     * @param [type]     $value [description]
23
+     */
24
+    public function __set(string $key, $value):void
25
+    {
26 26
     if (is_object($this->payload)) {
27
-      $this->payload->$key = $value;
28
-      return;
27
+        $this->payload->$key = $value;
28
+        return;
29 29
     }
30 30
     $this->payload[$key] = $value;
31
-  }
32
-  /**
33
-   * [__unset description]
34
-   * @date  2019-11-02
35
-   * @param string     $key [description]
36
-   */
37
-  public function __unset(string $key):void
38
-  {
31
+    }
32
+    /**
33
+     * [__unset description]
34
+     * @date  2019-11-02
35
+     * @param string     $key [description]
36
+     */
37
+    public function __unset(string $key):void
38
+    {
39 39
     if (is_object($this->payload)) {
40
-      unset($this->payload->$key);
41
-      return;
40
+        unset($this->payload->$key);
41
+        return;
42 42
     }
43 43
     unset($this->payload[$key]);
44
-  }
45
-  /**
46
-   * [__get description]
47
-   * @date   2019-11-02
48
-   * @param  string     $key [description]
49
-   * @return [type]          [description]
50
-   */
51
-  public function __get(string $key)
52
-  {
44
+    }
45
+    /**
46
+     * [__get description]
47
+     * @date   2019-11-02
48
+     * @param  string     $key [description]
49
+     * @return [type]          [description]
50
+     */
51
+    public function __get(string $key)
52
+    {
53 53
     if (is_object($this->payload)) return $this->payload->$key;
54 54
     return $this->payload[$key];
55
-  }
56
-  /**
57
-   * [__toString description]
58
-   * @date   2019-11-03
59
-   * @return string     [description]
60
-   */
61
-  public function __toString():string
62
-  {
55
+    }
56
+    /**
57
+     * [__toString description]
58
+     * @date   2019-11-03
59
+     * @return string     [description]
60
+     */
61
+    public function __toString():string
62
+    {
63 63
     $buff = $refactor->toArray();
64 64
     if ($buff != null) return json_encode($buff);
65 65
 
66 66
     return json_encode($this->payload);
67
-  }
68
-  /**
69
-   * [__debugInfo description]
70
-   * @date   2019-11-03
71
-   * @return [type]     [description]
72
-   */
73
-  public function __debugInfo():array
74
-  {
67
+    }
68
+    /**
69
+     * [__debugInfo description]
70
+     * @date   2019-11-03
71
+     * @return [type]     [description]
72
+     */
73
+    public function __debugInfo():array
74
+    {
75 75
     return [
76
-      'payload' => $this->payload
76
+        'payload' => $this->payload
77 77
     ];
78
-  }
79
-  /**
80
-   * [setPayload description]
81
-   * @date  2019-11-02
82
-   * @param [type]     $payload [description]
83
-   */
84
-  public function setPayload($payload):void
85
-  {
78
+    }
79
+    /**
80
+     * [setPayload description]
81
+     * @date  2019-11-02
82
+     * @param [type]     $payload [description]
83
+     */
84
+    public function setPayload($payload):void
85
+    {
86 86
     $this->payload = $payload;
87
-  }
88
-  /**
89
-   * [set_payload description]
90
-   * @date  2019-11-02
91
-   * @param array      $payload [description]
92
-   */
93
-  public function switchPayload(&$payload):void
94
-  {
87
+    }
88
+    /**
89
+     * [set_payload description]
90
+     * @date  2019-11-02
91
+     * @param array      $payload [description]
92
+     */
93
+    public function switchPayload(&$payload):void
94
+    {
95 95
     $this->payload =& $payload;
96
-  }
97
-  /**
98
-   * [toArray description]
99
-   * @date   2019-11-02
100
-   * @return array      [description]
101
-   */
102
-  public function toArray():array
103
-  {
96
+    }
97
+    /**
98
+     * [toArray description]
99
+     * @date   2019-11-02
100
+     * @return array      [description]
101
+     */
102
+    public function toArray():array
103
+    {
104 104
     if (is_array($this->payload)) return $this->payload;
105 105
     return json_decode(json_encode($this->payload), true);
106
-  }
106
+    }
107 107
 }
108 108
 ?>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
    * @date  2019-11-02
12 12
    * @param array      $payload [description]
13 13
    */
14
-  public function __construct($payload=[])
14
+  public function __construct($payload = [])
15 15
   {
16 16
     $this->payload = $payload;
17 17
   }
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
    */
93 93
   public function switchPayload(&$payload):void
94 94
   {
95
-    $this->payload =& $payload;
95
+    $this->payload = & $payload;
96 96
   }
97 97
   /**
98 98
    * [toArray description]
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -50,7 +50,9 @@  discard block
 block discarded – undo
50 50
    */
51 51
   public function __get(string $key)
52 52
   {
53
-    if (is_object($this->payload)) return $this->payload->$key;
53
+    if (is_object($this->payload)) {
54
+        return $this->payload->$key;
55
+    }
54 56
     return $this->payload[$key];
55 57
   }
56 58
   /**
@@ -61,7 +63,9 @@  discard block
 block discarded – undo
61 63
   public function __toString():string
62 64
   {
63 65
     $buff = $refactor->toArray();
64
-    if ($buff != null) return json_encode($buff);
66
+    if ($buff != null) {
67
+        return json_encode($buff);
68
+    }
65 69
 
66 70
     return json_encode($this->payload);
67 71
   }
@@ -101,7 +105,9 @@  discard block
 block discarded – undo
101 105
    */
102 106
   public function toArray():array
103 107
   {
104
-    if (is_array($this->payload)) return $this->payload;
108
+    if (is_array($this->payload)) {
109
+        return $this->payload;
110
+    }
105 111
     return json_decode(json_encode($this->payload), true);
106 112
   }
107 113
 }
Please login to merge, or discard this patch.
libraries/RefactorCI.php 3 patches
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -3,31 +3,31 @@  discard block
 block discarded – undo
3 3
 
4 4
 class RefactorCI
5 5
 {
6
-  /**
7
-   * [private description]
8
-   * @var [type]
9
-   */
10
-  private $ci;
6
+    /**
7
+     * [private description]
8
+     * @var [type]
9
+     */
10
+    private $ci;
11 11
 
12
-  /**
13
-   * [private description]
14
-   * @var [type]
15
-   */
16
-  private $primaryKey;
12
+    /**
13
+     * [private description]
14
+     * @var [type]
15
+     */
16
+    private $primaryKey;
17 17
 
18
-  /**
19
-   * [public description]
20
-   * @var [type]
21
-   */
22
-  public const PACKAGE = 'francis94c/refactor-ci';
18
+    /**
19
+     * [public description]
20
+     * @var [type]
21
+     */
22
+    public const PACKAGE = 'francis94c/refactor-ci';
23 23
 
24
-  /**
25
-   * [__construct description]
26
-   * @date  2020-04-10
27
-   * @param [type]     $params [description]
28
-   */
29
-  public function __construct($params=null)
30
-  {
24
+    /**
25
+     * [__construct description]
26
+     * @date  2020-04-10
27
+     * @param [type]     $params [description]
28
+     */
29
+    public function __construct($params=null)
30
+    {
31 31
     $this->ci =& get_instance();
32 32
     $this->ci->load->config("refactor", false, true);
33 33
     $this->ci->load->splint('francis94c/jsonp', '+JSONP', null, 'jsonp');
@@ -35,209 +35,209 @@  discard block
 block discarded – undo
35 35
     $this->init($params == null ? [] : $params);
36 36
 
37 37
     spl_autoload_register(function($name) {
38
-      if ($name == 'RefactorPayload') {
38
+        if ($name == 'RefactorPayload') {
39 39
         require(APPPATH . 'splints/' . self::PACKAGE . '/libraries/RefactorPayload.php');
40 40
         return;
41
-      }
41
+        }
42 42
 
43
-      if (file_exists(APPPATH . "payloads/$name.php")) {
43
+        if (file_exists(APPPATH . "payloads/$name.php")) {
44 44
         require(APPPATH . "payloads/$name.php");
45 45
         return;
46
-      }
46
+        }
47 47
 
48
-      if (file_exists(APPPATH . "libraries/refactor/$name.php")) {
48
+        if (file_exists(APPPATH . "libraries/refactor/$name.php")) {
49 49
         require(APPPATH . "libraries/refactor/$name.php"); // @deprecated
50
-      }      
50
+        }      
51 51
     });
52
-  }
53
-  /**
54
-   * [init description]
55
-   * @date  2019-11-02
56
-   * @param array      $params [description]
57
-   */
58
-  public function init(array $params):void
59
-  {
52
+    }
53
+    /**
54
+     * [init description]
55
+     * @date  2019-11-02
56
+     * @param array      $params [description]
57
+     */
58
+    public function init(array $params):void
59
+    {
60 60
     $this->primaryKey = $params['primary_key'] ?? 'id';
61
-  }
62
-  /**
63
-   * [load description]
64
-   * @date   2019-11-02
65
-   * @return RefactorCI [description]
66
-   */
67
-  public function load($class):RefactorCI
68
-  {
61
+    }
62
+    /**
63
+     * [load description]
64
+     * @date   2019-11-02
65
+     * @return RefactorCI [description]
66
+     */
67
+    public function load($class):RefactorCI
68
+    {
69 69
     require_once(APPPATH.'libraries/refactor/'.$class.'.php');
70 70
     return $this;
71
-  }
72
-  /**
73
-   * [payload description]
74
-   * @date   2019-11-02
75
-   * @param  string     $class  [description]
76
-   * @param  [type]     $object [description]
77
-   * @return [type]             [description]
78
-   */
79
-  public function payload(string $class, $object)
80
-  {
71
+    }
72
+    /**
73
+     * [payload description]
74
+     * @date   2019-11-02
75
+     * @param  string     $class  [description]
76
+     * @param  [type]     $object [description]
77
+     * @return [type]             [description]
78
+     */
79
+    public function payload(string $class, $object)
80
+    {
81 81
     return (new $class($object))->toArray();
82
-  }
83
-  /**
84
-   * [array description]
85
-   * @date   2019-11-02
86
-   * @param  string     $class [description]
87
-   * @param  array      $array [description]
88
-   * @return array             [description]
89
-   */
90
-  public function array(string $class, array $array):array
91
-  {
82
+    }
83
+    /**
84
+     * [array description]
85
+     * @date   2019-11-02
86
+     * @param  string     $class [description]
87
+     * @param  array      $array [description]
88
+     * @return array             [description]
89
+     */
90
+    public function array(string $class, array $array):array
91
+    {
92 92
     $refactor = new $class();
93 93
     $buff;
94 94
     for ($x = 0; $x < count($array); $x++) {
95
-      $refactor->switchPayload($array[$x]);
96
-      $buff = $refactor->toArray();
97
-      if ($buff != null) $array[$x] = $buff;
95
+        $refactor->switchPayload($array[$x]);
96
+        $buff = $refactor->toArray();
97
+        if ($buff != null) $array[$x] = $buff;
98 98
     }
99 99
     return $array;
100
-  }
101
-  /**
102
-   * [run description]
103
-   * @param array|string  $object   [description]
104
-   * @param string        $ruleName [description]
105
-   */
106
-  function run(array &$object, $ruleName):void
107
-  {
100
+    }
101
+    /**
102
+     * [run description]
103
+     * @param array|string  $object   [description]
104
+     * @param string        $ruleName [description]
105
+     */
106
+    function run(array &$object, $ruleName):void
107
+    {
108 108
     if ($object == null) return;
109 109
     // Reolve Rules.
110 110
     if (is_scalar($ruleName)) {
111
-      $rule = $this->ci->config->item("refactor_$ruleName");
111
+        $rule = $this->ci->config->item("refactor_$ruleName");
112 112
     } else {
113
-      // Rule was probablt passed in as an array (associative) and we support
114
-      // that.
115
-      $rule = is_array($ruleName) ? $ruleName : null;
113
+        // Rule was probablt passed in as an array (associative) and we support
114
+        // that.
115
+        $rule = is_array($ruleName) ? $ruleName : null;
116 116
     }
117 117
 
118 118
     if ($rule == null) return; // No need to go further as rule doesn't exist.
119 119
     // Keep
120 120
     if (isset($rule['keep'])) {
121
-      $keys = array_keys($object);
122
-      for ($x = 0; $x < count($object); $x++) {
121
+        $keys = array_keys($object);
122
+        for ($x = 0; $x < count($object); $x++) {
123 123
         if (!in_array($keys[$X], $rule['keep'])) {
124
-          unset($object[$keys[$x]]);
124
+            unset($object[$keys[$x]]);
125
+        }
125 126
         }
126
-      }
127 127
     }
128 128
     // Unset
129 129
     if (isset($rule['unset'])) {
130
-      $this->unset_values($object, $rule);
130
+        $this->unset_values($object, $rule);
131 131
     }
132 132
     // Replace
133 133
     if (isset($rule['replace'])) {
134
-      $this->replace_fields($object, $rule);
134
+        $this->replace_fields($object, $rule);
135 135
     }
136 136
     // Bools
137 137
     if (isset($rule['bools'])) {
138
-      foreach($rule['bools'] as $boolKey) {
138
+        foreach($rule['bools'] as $boolKey) {
139 139
         $object[$boolKey] = $object[$boolKey] == 1 || $object[$boolKey] == 'true';
140
-      }
140
+        }
141 141
     }
142 142
     // Cast
143 143
     if (isset($rule['cast']))  {
144
-      $this->cast_fields($object, $rule);
144
+        $this->cast_fields($object, $rule);
145 145
     }
146 146
     // Inflate
147 147
     if (isset($rule['inflate'])) {
148
-      foreach($rule['inflate'] as $field => $data) {
148
+        foreach($rule['inflate'] as $field => $data) {
149 149
         $ids = json_decode($object[$field], true);
150 150
         if (is_scalar($ids)) {
151
-          // JSON Array wasn't supplied. Let's treat it as a scaler ID.
152
-          $this->ci->db->where($this->primaryKey, $ids);
153
-          $query = $this->ci->db->get($data['table']);
154
-          if ($query->num_rows() == 0) {
151
+            // JSON Array wasn't supplied. Let's treat it as a scaler ID.
152
+            $this->ci->db->where($this->primaryKey, $ids);
153
+            $query = $this->ci->db->get($data['table']);
154
+            if ($query->num_rows() == 0) {
155 155
             $object[$field] = json_encode (json_decode ("{}"));
156 156
             continue;
157
-          }
158
-          $object[$field] = $query->result_array()[0];
159
-          if (isset($data['refactor'])) $this->run($object[$field], $data['refactor']);
160
-          continue;
157
+            }
158
+            $object[$field] = $query->result_array()[0];
159
+            if (isset($data['refactor'])) $this->run($object[$field], $data['refactor']);
160
+            continue;
161 161
         }
162 162
         if (isset($data['path'])) {
163
-          if ($ids == null) return;
164
-          $object[$field] = $ids;
165
-          $this->ci->jsonp->parse($object[$field]);
166
-          if (is_array($object[$field])) {
163
+            if ($ids == null) return;
164
+            $object[$field] = $ids;
165
+            $this->ci->jsonp->parse($object[$field]);
166
+            if (is_array($object[$field])) {
167 167
             $refs = $this->ci->jsonp->get_reference($data['path']);
168 168
             for ($x = 0; $x < count($refs); $x++) {
169
-              $refs[$x] = $this->inflate_value($data['table'], $refs[$x]);
170
-              // Recursion
171
-              if (isset($data['refactor'])) $this->run($refs[$x], $data['refactor']);
169
+                $refs[$x] = $this->inflate_value($data['table'], $refs[$x]);
170
+                // Recursion
171
+                if (isset($data['refactor'])) $this->run($refs[$x], $data['refactor']);
172 172
             }
173
-          } else {
173
+            } else {
174 174
             $this->ci->jsonp->set($data['path'], $this->inflate_value($data['table'], $ids));
175 175
             // Recursion
176 176
             if (isset($data['refactor'])) $this->run($this->ci->jsonp->get_reference($data['path']), $data['refactor']);
177
-          }
178
-          return;
177
+            }
178
+            return;
179 179
         }
180 180
         $object[$field] = [];
181 181
         if ($ids == null) return;
182 182
         foreach($ids as $id) {
183
-          $this->ci->db->where($this->primaryKey, $id);
184
-          $query = $this->ci->db->get($data['table']);
185
-          if ($query->num_rows() == 0) {
183
+            $this->ci->db->where($this->primaryKey, $id);
184
+            $query = $this->ci->db->get($data['table']);
185
+            if ($query->num_rows() == 0) {
186 186
             continue;
187
-          }
188
-          $object[$field][] = $query->result_array()[0];
189
-          // Recursion
190
-          if (isset($data['refactor'])) $this->run($object[$field][count($object[$field]) - 1], $data['refactor']);
187
+            }
188
+            $object[$field][] = $query->result_array()[0];
189
+            // Recursion
190
+            if (isset($data['refactor'])) $this->run($object[$field][count($object[$field]) - 1], $data['refactor']);
191
+        }
191 192
         }
192
-      }
193 193
     }
194
-  }
195
-  private function inflate_value(string $table, $value)
196
-  {
194
+    }
195
+    private function inflate_value(string $table, $value)
196
+    {
197 197
     $this->ci->db->where($this->primaryKey, $value);
198 198
     $query = $this->ci->db->get($table);
199 199
     return $query->num_rows() > 0 ? $query->result_array()[0] : null;
200
-  }
201
-  /**
202
-   * [unset_values description]
203
-   * @param array  $object Object to Refactor.
204
-   * @param array  $rule   Rule data, containing keys to unset in  the given
205
-   *                       associative array.
206
-   */
207
-  private function unset_values(array &$object, &$rule):void {
200
+    }
201
+    /**
202
+     * [unset_values description]
203
+     * @param array  $object Object to Refactor.
204
+     * @param array  $rule   Rule data, containing keys to unset in  the given
205
+     *                       associative array.
206
+     */
207
+    private function unset_values(array &$object, &$rule):void {
208 208
     foreach($rule['unset'] as $key) {
209
-      unset($object[$key]);
210
-    }
211
-  }
212
-  /**
213
-   * [replace_fields description]
214
-   * @param array  $object [description]
215
-   * @param [type] $rule   [description]
216
-   */
217
-  private function replace_fields(array &$object, &$rule):void
218
-  {
209
+        unset($object[$key]);
210
+    }
211
+    }
212
+    /**
213
+     * [replace_fields description]
214
+     * @param array  $object [description]
215
+     * @param [type] $rule   [description]
216
+     */
217
+    private function replace_fields(array &$object, &$rule):void
218
+    {
219 219
     foreach ($rule['replace'] as $oldKey => $newKey) {
220
-      $object[$newKey] = $object[$oldKey];
221
-      unset($object[$oldKey]);
222
-    }
223
-  }
224
-  /**
225
-   * [cast_fields description]
226
-   * @param array  $object [description]
227
-   * @param [type] $rule   [description]
228
-   */
229
-  private function cast_fields(array &$object, &$rule):void
230
-  {
220
+        $object[$newKey] = $object[$oldKey];
221
+        unset($object[$oldKey]);
222
+    }
223
+    }
224
+    /**
225
+     * [cast_fields description]
226
+     * @param array  $object [description]
227
+     * @param [type] $rule   [description]
228
+     */
229
+    private function cast_fields(array &$object, &$rule):void
230
+    {
231 231
     foreach ($rule['cast'] as $key => $type) {
232
-      switch ($type) {
232
+        switch ($type) {
233 233
         case 'int':
234 234
           $object[$key] = (int) $object[$key];
235
-          break;
235
+            break;
236 236
         case 'string':
237 237
           $object[$key] = (string) $object[$key];
238
-          break;
239
-      }
238
+            break;
239
+        }
240
+    }
240 241
     }
241
-  }
242 242
 }
243 243
 ?>
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -26,9 +26,9 @@  discard block
 block discarded – undo
26 26
    * @date  2020-04-10
27 27
    * @param [type]     $params [description]
28 28
    */
29
-  public function __construct($params=null)
29
+  public function __construct($params = null)
30 30
   {
31
-    $this->ci =& get_instance();
31
+    $this->ci = & get_instance();
32 32
     $this->ci->load->config("refactor", false, true);
33 33
     $this->ci->load->splint('francis94c/jsonp', '+JSONP', null, 'jsonp');
34 34
 
@@ -36,17 +36,17 @@  discard block
 block discarded – undo
36 36
 
37 37
     spl_autoload_register(function($name) {
38 38
       if ($name == 'RefactorPayload') {
39
-        require(APPPATH . 'splints/' . self::PACKAGE . '/libraries/RefactorPayload.php');
39
+        require(APPPATH.'splints/'.self::PACKAGE.'/libraries/RefactorPayload.php');
40 40
         return;
41 41
       }
42 42
 
43
-      if (file_exists(APPPATH . "payloads/$name.php")) {
44
-        require(APPPATH . "payloads/$name.php");
43
+      if (file_exists(APPPATH."payloads/$name.php")) {
44
+        require(APPPATH."payloads/$name.php");
45 45
         return;
46 46
       }
47 47
 
48
-      if (file_exists(APPPATH . "libraries/refactor/$name.php")) {
49
-        require(APPPATH . "libraries/refactor/$name.php"); // @deprecated
48
+      if (file_exists(APPPATH."libraries/refactor/$name.php")) {
49
+        require(APPPATH."libraries/refactor/$name.php"); // @deprecated
50 50
       }      
51 51
     });
52 52
   }
@@ -135,24 +135,24 @@  discard block
 block discarded – undo
135 135
     }
136 136
     // Bools
137 137
     if (isset($rule['bools'])) {
138
-      foreach($rule['bools'] as $boolKey) {
138
+      foreach ($rule['bools'] as $boolKey) {
139 139
         $object[$boolKey] = $object[$boolKey] == 1 || $object[$boolKey] == 'true';
140 140
       }
141 141
     }
142 142
     // Cast
143
-    if (isset($rule['cast']))  {
143
+    if (isset($rule['cast'])) {
144 144
       $this->cast_fields($object, $rule);
145 145
     }
146 146
     // Inflate
147 147
     if (isset($rule['inflate'])) {
148
-      foreach($rule['inflate'] as $field => $data) {
148
+      foreach ($rule['inflate'] as $field => $data) {
149 149
         $ids = json_decode($object[$field], true);
150 150
         if (is_scalar($ids)) {
151 151
           // JSON Array wasn't supplied. Let's treat it as a scaler ID.
152 152
           $this->ci->db->where($this->primaryKey, $ids);
153 153
           $query = $this->ci->db->get($data['table']);
154 154
           if ($query->num_rows() == 0) {
155
-            $object[$field] = json_encode (json_decode ("{}"));
155
+            $object[$field] = json_encode(json_decode("{}"));
156 156
             continue;
157 157
           }
158 158
           $object[$field] = $query->result_array()[0];
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
         }
180 180
         $object[$field] = [];
181 181
         if ($ids == null) return;
182
-        foreach($ids as $id) {
182
+        foreach ($ids as $id) {
183 183
           $this->ci->db->where($this->primaryKey, $id);
184 184
           $query = $this->ci->db->get($data['table']);
185 185
           if ($query->num_rows() == 0) {
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
    *                       associative array.
206 206
    */
207 207
   private function unset_values(array &$object, &$rule):void {
208
-    foreach($rule['unset'] as $key) {
208
+    foreach ($rule['unset'] as $key) {
209 209
       unset($object[$key]);
210 210
     }
211 211
   }
Please login to merge, or discard this patch.
Braces   +28 added lines, -9 removed lines patch added patch discarded remove patch
@@ -94,7 +94,9 @@  discard block
 block discarded – undo
94 94
     for ($x = 0; $x < count($array); $x++) {
95 95
       $refactor->switchPayload($array[$x]);
96 96
       $buff = $refactor->toArray();
97
-      if ($buff != null) $array[$x] = $buff;
97
+      if ($buff != null) {
98
+          $array[$x] = $buff;
99
+      }
98 100
     }
99 101
     return $array;
100 102
   }
@@ -105,7 +107,9 @@  discard block
 block discarded – undo
105 107
    */
106 108
   function run(array &$object, $ruleName):void
107 109
   {
108
-    if ($object == null) return;
110
+    if ($object == null) {
111
+        return;
112
+    }
109 113
     // Reolve Rules.
110 114
     if (is_scalar($ruleName)) {
111 115
       $rule = $this->ci->config->item("refactor_$ruleName");
@@ -115,7 +119,10 @@  discard block
 block discarded – undo
115 119
       $rule = is_array($ruleName) ? $ruleName : null;
116 120
     }
117 121
 
118
-    if ($rule == null) return; // No need to go further as rule doesn't exist.
122
+    if ($rule == null) {
123
+        return;
124
+    }
125
+    // No need to go further as rule doesn't exist.
119 126
     // Keep
120 127
     if (isset($rule['keep'])) {
121 128
       $keys = array_keys($object);
@@ -156,11 +163,15 @@  discard block
 block discarded – undo
156 163
             continue;
157 164
           }
158 165
           $object[$field] = $query->result_array()[0];
159
-          if (isset($data['refactor'])) $this->run($object[$field], $data['refactor']);
166
+          if (isset($data['refactor'])) {
167
+              $this->run($object[$field], $data['refactor']);
168
+          }
160 169
           continue;
161 170
         }
162 171
         if (isset($data['path'])) {
163
-          if ($ids == null) return;
172
+          if ($ids == null) {
173
+              return;
174
+          }
164 175
           $object[$field] = $ids;
165 176
           $this->ci->jsonp->parse($object[$field]);
166 177
           if (is_array($object[$field])) {
@@ -168,17 +179,23 @@  discard block
 block discarded – undo
168 179
             for ($x = 0; $x < count($refs); $x++) {
169 180
               $refs[$x] = $this->inflate_value($data['table'], $refs[$x]);
170 181
               // Recursion
171
-              if (isset($data['refactor'])) $this->run($refs[$x], $data['refactor']);
182
+              if (isset($data['refactor'])) {
183
+                  $this->run($refs[$x], $data['refactor']);
184
+              }
172 185
             }
173 186
           } else {
174 187
             $this->ci->jsonp->set($data['path'], $this->inflate_value($data['table'], $ids));
175 188
             // Recursion
176
-            if (isset($data['refactor'])) $this->run($this->ci->jsonp->get_reference($data['path']), $data['refactor']);
189
+            if (isset($data['refactor'])) {
190
+                $this->run($this->ci->jsonp->get_reference($data['path']), $data['refactor']);
191
+            }
177 192
           }
178 193
           return;
179 194
         }
180 195
         $object[$field] = [];
181
-        if ($ids == null) return;
196
+        if ($ids == null) {
197
+            return;
198
+        }
182 199
         foreach($ids as $id) {
183 200
           $this->ci->db->where($this->primaryKey, $id);
184 201
           $query = $this->ci->db->get($data['table']);
@@ -187,7 +204,9 @@  discard block
 block discarded – undo
187 204
           }
188 205
           $object[$field][] = $query->result_array()[0];
189 206
           // Recursion
190
-          if (isset($data['refactor'])) $this->run($object[$field][count($object[$field]) - 1], $data['refactor']);
207
+          if (isset($data['refactor'])) {
208
+              $this->run($object[$field][count($object[$field]) - 1], $data['refactor']);
209
+          }
191 210
         }
192 211
       }
193 212
     }
Please login to merge, or discard this patch.
libraries/RefactorArray.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -3,55 +3,55 @@
 block discarded – undo
3 3
 
4 4
 class RefactorArray implements ArrayAccess, Countable
5 5
 {
6
-  /**
7
-   * [private description]
8
-   * @var [type]
9
-   */
10
-  private $data = array();
11
-  /**
12
-   * [offsetSet description]
13
-   * @date  2019-11-02
14
-   * @param [type]     $offset [description]
15
-   * @param [type]     $value  [description]
16
-   */
17
-  public function offsetSet($offset, $value)
18
-  {
6
+    /**
7
+     * [private description]
8
+     * @var [type]
9
+     */
10
+    private $data = array();
11
+    /**
12
+     * [offsetSet description]
13
+     * @date  2019-11-02
14
+     * @param [type]     $offset [description]
15
+     * @param [type]     $value  [description]
16
+     */
17
+    public function offsetSet($offset, $value)
18
+    {
19 19
     $this->data[$offset] = $value;
20
-  }
21
-  /**
22
-   * [offsetExists description]
23
-   * @date  2019-11-02
24
-   * @param [type]     $offset [description]
25
-   */
26
-  public function offsetExists($offset)
27
-  {
20
+    }
21
+    /**
22
+     * [offsetExists description]
23
+     * @date  2019-11-02
24
+     * @param [type]     $offset [description]
25
+     */
26
+    public function offsetExists($offset)
27
+    {
28 28
     return isset($this->data[$offset]);
29
-  }
30
-  /**
31
-   * [offsetUnset description]
32
-   * @date  2019-11-02
33
-   * @param [type]     $offset [description]
34
-   */
35
-  public function offsetUnset($offset)
36
-  {
29
+    }
30
+    /**
31
+     * [offsetUnset description]
32
+     * @date  2019-11-02
33
+     * @param [type]     $offset [description]
34
+     */
35
+    public function offsetUnset($offset)
36
+    {
37 37
     unset($this->data[$offset]);
38
-  }
39
-  /**
40
-   * [offsetGet description]
41
-   * @date  2019-11-02
42
-   * @param [type]     $offset [description]
43
-   */
44
-  public function offsetGet($offset)
45
-  {
38
+    }
39
+    /**
40
+     * [offsetGet description]
41
+     * @date  2019-11-02
42
+     * @param [type]     $offset [description]
43
+     */
44
+    public function offsetGet($offset)
45
+    {
46 46
     return ($this->offsetExists($offset)) ? $this->data[$offset] : null;
47
-  }
48
-  /**
49
-   * [count description]
50
-   * @date   2019-11-02
51
-   * @return [type]     [description]
52
-   */
53
-  public function count()
54
-  {
47
+    }
48
+    /**
49
+     * [count description]
50
+     * @date   2019-11-02
51
+     * @return [type]     [description]
52
+     */
53
+    public function count()
54
+    {
55 55
     return count($this->_data);
56
-  }
56
+    }
57 57
 }
Please login to merge, or discard this patch.
phpunit/RefactorTest.php 2 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -3,54 +3,54 @@
 block discarded – undo
3 3
 use PHPUnit\Framework\TestCase;
4 4
 
5 5
 class RefactorTest extends TestCase {
6
-  /**
7
-   * Code Igniter Instance.
8
-   * @var object
9
-   */
10
-  private static $ci;
11
-  /**
12
-   * Package name for simplicity
13
-   * @var string
14
-   */
15
-  private const PACKAGE = "francis94c/refactor-ci";
6
+    /**
7
+     * Code Igniter Instance.
8
+     * @var object
9
+     */
10
+    private static $ci;
11
+    /**
12
+     * Package name for simplicity
13
+     * @var string
14
+     */
15
+    private const PACKAGE = "francis94c/refactor-ci";
16 16
 
17
-  /**
18
-   * Prerquisites for the Unit Tests.
19
-   *
20
-   * @covers JWT::__construct
21
-   */
22
-  public static function setUpBeforeClass(): void {
17
+    /**
18
+     * Prerquisites for the Unit Tests.
19
+     *
20
+     * @covers JWT::__construct
21
+     */
22
+    public static function setUpBeforeClass(): void {
23 23
     self::$ci =& get_instance();
24
-  }
25
-  /**
26
-   * [testLoadPackage description]
27
-   */
28
-  public function testLoadPackage():void {
24
+    }
25
+    /**
26
+     * [testLoadPackage description]
27
+     */
28
+    public function testLoadPackage():void {
29 29
     self::$ci->load->package(self::PACKAGE);
30 30
     $this->assertTrue(isset(self::$ci->refactor));
31
-  }
32
-  /**
33
-   * [testDirectUnsetRule description]
34
-   *
35
-   * @depends testLoadPackage
36
-   */
37
-  public function testDirectUnsetRule():void {
31
+    }
32
+    /**
33
+     * [testDirectUnsetRule description]
34
+     *
35
+     * @depends testLoadPackage
36
+     */
37
+    public function testDirectUnsetRule():void {
38 38
     $payload = [
39
-      'name'     => 'collins',
40
-      'pc_brand' => 'HP',
41
-      'phone'    => '+2349086756453',
42
-      'school'   => 'Delloite',
43
-      'company'  => 'Google'
39
+        'name'     => 'collins',
40
+        'pc_brand' => 'HP',
41
+        'phone'    => '+2349086756453',
42
+        'school'   => 'Delloite',
43
+        'company'  => 'Google'
44 44
     ];
45 45
     $rule = [
46
-      'unset' => [
46
+        'unset' => [
47 47
         'school',
48 48
         'phone'
49
-      ]
49
+        ]
50 50
     ];
51 51
     self::$ci->refactor->run($payload, $rule);
52 52
     $this->assertFalse(isset($payload['school']));
53 53
     $this->assertFalse(isset($payload['phone']));
54 54
     $this->assertTrue(isset($payload['company']));
55
-  }
55
+    }
56 56
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
    * @covers JWT::__construct
21 21
    */
22 22
   public static function setUpBeforeClass(): void {
23
-    self::$ci =& get_instance();
23
+    self::$ci = & get_instance();
24 24
   }
25 25
   /**
26 26
    * [testLoadPackage description]
Please login to merge, or discard this patch.