Passed
Push — master ( ac7f19...ab110a )
by Francis
01:08
created
libraries/RefactorCI.php 2 patches
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -3,125 +3,125 @@
 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
-  private $primaryKey;
12
+    private $primaryKey;
13 13
 
14
-  function __construct($params=null) {
14
+    function __construct($params=null) {
15 15
     $this->ci =& get_instance();
16 16
     $this->ci->load->config("refactor", false, true);
17 17
     $this->init($params == null ? [] : $params);
18
-  }
18
+    }
19 19
 
20
-  public function init(array $params):void {
20
+    public function init(array $params):void {
21 21
     $this->primaryKey = $params['primary_key'] ?? 'id';
22
-  }
23
-  /**
24
-   * [run description]
25
-   * @param array|string  $object   [description]
26
-   * @param string        $ruleName [description]
27
-   */
28
-  function run(array &$object, $ruleName):void {
22
+    }
23
+    /**
24
+     * [run description]
25
+     * @param array|string  $object   [description]
26
+     * @param string        $ruleName [description]
27
+     */
28
+    function run(array &$object, $ruleName):void {
29 29
     // Reolve Rules.
30 30
     if (is_scalar($ruleName)) {
31
-      $rule = $this->ci->config->item("refactor_$ruleName");
31
+        $rule = $this->ci->config->item("refactor_$ruleName");
32 32
     } else {
33
-      // Rule was probablt passed in as an array (associative) and we support
34
-      // that.
35
-      $rule = is_array($ruleName) ? $ruleName : null;
33
+        // Rule was probablt passed in as an array (associative) and we support
34
+        // that.
35
+        $rule = is_array($ruleName) ? $ruleName : null;
36 36
     }
37 37
 
38 38
     if ($rule == null) return; // No need to go further as rule doesn't exist.
39 39
     // Unset
40 40
     if (isset($rule['unset'])) {
41
-      $this->unset_values($object, $rule);
41
+        $this->unset_values($object, $rule);
42 42
     }
43 43
     // Replace
44 44
     if (isset($rule['replace'])) {
45
-      $this->replace_fields($object, $rule);
45
+        $this->replace_fields($object, $rule);
46 46
     }
47 47
     // Bools
48 48
     if (isset($rule['bools'])) {
49
-      foreach($rule['bools'] as $boolKey) {
49
+        foreach($rule['bools'] as $boolKey) {
50 50
         $object[$boolKey] = $object[$boolKey] == 1 || $object[$boolKey] == 'true';
51
-      }
51
+        }
52 52
     }
53 53
     // Cast
54 54
     if (isset($rule['cast']))  {
55
-      $this->cast_fields($object, $rule);
55
+        $this->cast_fields($object, $rule);
56 56
     }
57 57
     // Objects
58 58
     if (isset($rule['objects'])) {
59
-      foreach($rule['objects'] as $field => $data) {
59
+        foreach($rule['objects'] as $field => $data) {
60 60
         $ids = json_decode($object[$field]);
61 61
         if (is_scalar($ids)) {
62
-          // JSON Array wasn't supplied. Let's treat it as a scaler ID.
63
-          $this->ci->db->where($this->primaryKey, $ids);
64
-          $query = $this->ci->db->get($data['table']);
65
-          if ($query->num_rows() == 0) {
62
+            // JSON Array wasn't supplied. Let's treat it as a scaler ID.
63
+            $this->ci->db->where($this->primaryKey, $ids);
64
+            $query = $this->ci->db->get($data['table']);
65
+            if ($query->num_rows() == 0) {
66 66
             $object[$field] = json_encode (json_decode ("{}"));
67 67
             continue;
68
-          }
69
-          $object[$field] = $query->result_array()[0];
70
-          if (isset($data['refactor'])) $this->run($object[$field], $data['refactor']);
71
-          continue;
68
+            }
69
+            $object[$field] = $query->result_array()[0];
70
+            if (isset($data['refactor'])) $this->run($object[$field], $data['refactor']);
71
+            continue;
72 72
         }
73 73
         $object[$field] = [];
74 74
         foreach($ids as $id) {
75
-          $this->ci->db->where($this->primaryKey, $id);
76
-          $query = $this->ci->db->get($data['table']);
77
-          if ($query->num_rows() == 0) {
75
+            $this->ci->db->where($this->primaryKey, $id);
76
+            $query = $this->ci->db->get($data['table']);
77
+            if ($query->num_rows() == 0) {
78 78
             continue;
79
-          }
80
-          $object[$field][] = $query->result_array()[0];
81
-          // Recursion
82
-          if (isset($data['refactor'])) $this->run($object[$field][count($object[$field]) - 1], $data['refactor']);
79
+            }
80
+            $object[$field][] = $query->result_array()[0];
81
+            // Recursion
82
+            if (isset($data['refactor'])) $this->run($object[$field][count($object[$field]) - 1], $data['refactor']);
83
+        }
83 84
         }
84
-      }
85 85
     }
86
-  }
87
-  /**
88
-   * [unset_values description]
89
-   * @param array  $object Object to Refactor.
90
-   * @param array  $rule   Rule data, containing keys to unset in  the given
91
-   *                       associative array.
92
-   */
93
-  private function unset_values(array &$object, &$rule):void {
86
+    }
87
+    /**
88
+     * [unset_values description]
89
+     * @param array  $object Object to Refactor.
90
+     * @param array  $rule   Rule data, containing keys to unset in  the given
91
+     *                       associative array.
92
+     */
93
+    private function unset_values(array &$object, &$rule):void {
94 94
     foreach($rule['unset'] as $key) {
95
-      unset($object[$key]);
95
+        unset($object[$key]);
96
+    }
96 97
     }
97
-  }
98
-  /**
99
-   * [replace_fields description]
100
-   * @param array  $object [description]
101
-   * @param [type] $rule   [description]
102
-   */
103
-  private function replace_fields(array &$object, &$rule):void {
98
+    /**
99
+     * [replace_fields description]
100
+     * @param array  $object [description]
101
+     * @param [type] $rule   [description]
102
+     */
103
+    private function replace_fields(array &$object, &$rule):void {
104 104
     foreach ($rule['replace'] as $oldKey => $newKey) {
105
-      $object[$newKey] = $object[$oldKey];
106
-      unset($object[$oldKey]);
105
+        $object[$newKey] = $object[$oldKey];
106
+        unset($object[$oldKey]);
107
+    }
107 108
     }
108
-  }
109
-  /**
110
-   * [cast_fields description]
111
-   * @param array  $object [description]
112
-   * @param [type] $rule   [description]
113
-   */
114
-  private function cast_fields(array &$object, &$rule):void {
109
+    /**
110
+     * [cast_fields description]
111
+     * @param array  $object [description]
112
+     * @param [type] $rule   [description]
113
+     */
114
+    private function cast_fields(array &$object, &$rule):void {
115 115
     foreach ($rule['cast'] as $key => $type) {
116
-      switch ($type) {
116
+        switch ($type) {
117 117
         case 'int':
118 118
           $object[$key] = (int) $object[$key];
119
-          break;
119
+            break;
120 120
         case 'string':
121 121
           $object[$key] = (string) $object[$key];
122
-          break;
123
-      }
122
+            break;
123
+        }
124
+    }
124 125
     }
125
-  }
126 126
 }
127 127
 ?>
Please login to merge, or discard this patch.
Braces   +10 added lines, -3 removed lines patch added patch discarded remove patch
@@ -35,7 +35,10 @@  discard block
 block discarded – undo
35 35
       $rule = is_array($ruleName) ? $ruleName : null;
36 36
     }
37 37
 
38
-    if ($rule == null) return; // No need to go further as rule doesn't exist.
38
+    if ($rule == null) {
39
+        return;
40
+    }
41
+    // No need to go further as rule doesn't exist.
39 42
     // Unset
40 43
     if (isset($rule['unset'])) {
41 44
       $this->unset_values($object, $rule);
@@ -67,7 +70,9 @@  discard block
 block discarded – undo
67 70
             continue;
68 71
           }
69 72
           $object[$field] = $query->result_array()[0];
70
-          if (isset($data['refactor'])) $this->run($object[$field], $data['refactor']);
73
+          if (isset($data['refactor'])) {
74
+              $this->run($object[$field], $data['refactor']);
75
+          }
71 76
           continue;
72 77
         }
73 78
         $object[$field] = [];
@@ -79,7 +84,9 @@  discard block
 block discarded – undo
79 84
           }
80 85
           $object[$field][] = $query->result_array()[0];
81 86
           // Recursion
82
-          if (isset($data['refactor'])) $this->run($object[$field][count($object[$field]) - 1], $data['refactor']);
87
+          if (isset($data['refactor'])) {
88
+              $this->run($object[$field][count($object[$field]) - 1], $data['refactor']);
89
+          }
83 90
         }
84 91
       }
85 92
     }
Please login to merge, or discard this patch.