| Conditions | 29 | 
| Paths | 1060 | 
| Total Lines | 85 | 
| Code Lines | 54 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 7 | ||
| Bugs | 0 | Features | 0 | 
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php  | 
            ||
| 79 | function run(array &$object, $ruleName):void  | 
            ||
| 80 |   { | 
            ||
| 81 | if ($object == null) return;  | 
            ||
| 82 | // Reolve Rules.  | 
            ||
| 83 |     if (is_scalar($ruleName)) { | 
            ||
| 84 |       $rule = $this->ci->config->item("refactor_$ruleName"); | 
            ||
| 85 |     } else { | 
            ||
| 86 | // Rule was probablt passed in as an array (associative) and we support  | 
            ||
| 87 | // that.  | 
            ||
| 88 | $rule = is_array($ruleName) ? $ruleName : null;  | 
            ||
| 89 | }  | 
            ||
| 90 | |||
| 91 | if ($rule == null) return; // No need to go further as rule doesn't exist.  | 
            ||
| 92 | // Keep  | 
            ||
| 93 |     if (isset($rule['keep'])) { | 
            ||
| 94 | $keys = array_keys($object);  | 
            ||
| 95 |       for ($x = 0; $x < count($object); $x++) { | 
            ||
| 96 |         if (!in_array($keys[$X], $rule['keep'])) { | 
            ||
| 97 | unset($object[$keys[$x]]);  | 
            ||
| 98 | }  | 
            ||
| 99 | }  | 
            ||
| 100 | }  | 
            ||
| 101 | // Unset  | 
            ||
| 102 |     if (isset($rule['unset'])) { | 
            ||
| 103 | $this->unset_values($object, $rule);  | 
            ||
| 104 | }  | 
            ||
| 105 | // Replace  | 
            ||
| 106 |     if (isset($rule['replace'])) { | 
            ||
| 107 | $this->replace_fields($object, $rule);  | 
            ||
| 108 | }  | 
            ||
| 109 | // Bools  | 
            ||
| 110 |     if (isset($rule['bools'])) { | 
            ||
| 111 |       foreach($rule['bools'] as $boolKey) { | 
            ||
| 112 | $object[$boolKey] = $object[$boolKey] == 1 || $object[$boolKey] == 'true';  | 
            ||
| 113 | }  | 
            ||
| 114 | }  | 
            ||
| 115 | // Cast  | 
            ||
| 116 |     if (isset($rule['cast']))  { | 
            ||
| 117 | $this->cast_fields($object, $rule);  | 
            ||
| 118 | }  | 
            ||
| 119 | // Inflate  | 
            ||
| 120 |     if (isset($rule['inflate'])) { | 
            ||
| 121 |       foreach($rule['inflate'] as $field => $data) { | 
            ||
| 122 | $ids = json_decode($object[$field], true);  | 
            ||
| 123 |         if (is_scalar($ids)) { | 
            ||
| 124 | // JSON Array wasn't supplied. Let's treat it as a scaler ID.  | 
            ||
| 125 | $this->ci->db->where($this->primaryKey, $ids);  | 
            ||
| 126 | $query = $this->ci->db->get($data['table']);  | 
            ||
| 127 |           if ($query->num_rows() == 0) { | 
            ||
| 128 |             $object[$field] = json_encode (json_decode ("{}")); | 
            ||
| 129 | continue;  | 
            ||
| 130 | }  | 
            ||
| 131 | $object[$field] = $query->result_array()[0];  | 
            ||
| 132 | if (isset($data['refactor'])) $this->run($object[$field], $data['refactor']);  | 
            ||
| 133 | continue;  | 
            ||
| 134 | }  | 
            ||
| 135 |         if (isset($data['path'])) { | 
            ||
| 136 | if ($ids == null) return;  | 
            ||
| 137 | $object[$field] = $ids;  | 
            ||
| 138 | $this->ci->jsonp->parse($object[$field]);  | 
            ||
| 139 |           if (is_array($object[$field])) { | 
            ||
| 140 | $refs = $this->ci->jsonp->get_reference($data['path']);  | 
            ||
| 141 |             for ($x = 0; $x < count($refs); $x++) { | 
            ||
| 142 | $refs[$x] = $this->inflate_value($data['table'], $refs[$x]);  | 
            ||
| 143 | // Recursion  | 
            ||
| 144 | if (isset($data['refactor'])) $this->run($refs[$x], $data['refactor']);  | 
            ||
| 145 | }  | 
            ||
| 146 |           } else { | 
            ||
| 147 | $this->ci->jsonp->set($data['path'], $this->inflate_value($data['table'], $ids));  | 
            ||
| 148 | // Recursion  | 
            ||
| 149 | if (isset($data['refactor'])) $this->run($this->ci->jsonp->get_reference($data['path']), $data['refactor']);  | 
            ||
| 150 | }  | 
            ||
| 151 | return;  | 
            ||
| 152 | }  | 
            ||
| 153 | $object[$field] = [];  | 
            ||
| 154 | if ($ids == null) return;  | 
            ||
| 155 |         foreach($ids as $id) { | 
            ||
| 156 | $this->ci->db->where($this->primaryKey, $id);  | 
            ||
| 157 | $query = $this->ci->db->get($data['table']);  | 
            ||
| 158 |           if ($query->num_rows() == 0) { | 
            ||
| 159 | continue;  | 
            ||
| 160 | }  | 
            ||
| 161 | $object[$field][] = $query->result_array()[0];  | 
            ||
| 162 | // Recursion  | 
            ||
| 163 | if (isset($data['refactor'])) $this->run($object[$field][count($object[$field]) - 1], $data['refactor']);  | 
            ||
| 164 | }  | 
            ||
| 217 |