@@ -20,7 +20,7 @@ |
||
| 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] |
@@ -3,54 +3,54 @@ |
||
| 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 | } |
@@ -4,213 +4,213 @@ |
||
| 4 | 4 | class RefactorCI |
| 5 | 5 | { |
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * [private description] |
|
| 9 | - * @var [type] |
|
| 10 | - */ |
|
| 11 | - private $ci; |
|
| 12 | - /** |
|
| 13 | - * [private description] |
|
| 14 | - * @var [type] |
|
| 15 | - */ |
|
| 16 | - private $primaryKey; |
|
| 7 | + /** |
|
| 8 | + * [private description] |
|
| 9 | + * @var [type] |
|
| 10 | + */ |
|
| 11 | + private $ci; |
|
| 12 | + /** |
|
| 13 | + * [private description] |
|
| 14 | + * @var [type] |
|
| 15 | + */ |
|
| 16 | + private $primaryKey; |
|
| 17 | 17 | |
| 18 | - function __construct($params=null) |
|
| 19 | - { |
|
| 18 | + function __construct($params=null) |
|
| 19 | + { |
|
| 20 | 20 | $this->ci =& get_instance(); |
| 21 | 21 | $this->ci->load->config("refactor", false, true); |
| 22 | 22 | $this->ci->load->splint('francis94c/jsonp', '+JSONP', null, 'jsonp'); |
| 23 | 23 | require_once('RefactorPayload.php'); |
| 24 | 24 | $this->init($params == null ? [] : $params); |
| 25 | - } |
|
| 26 | - /** |
|
| 27 | - * [init description] |
|
| 28 | - * @date 2019-11-02 |
|
| 29 | - * @param array $params [description] |
|
| 30 | - */ |
|
| 31 | - public function init(array $params):void |
|
| 32 | - { |
|
| 25 | + } |
|
| 26 | + /** |
|
| 27 | + * [init description] |
|
| 28 | + * @date 2019-11-02 |
|
| 29 | + * @param array $params [description] |
|
| 30 | + */ |
|
| 31 | + public function init(array $params):void |
|
| 32 | + { |
|
| 33 | 33 | $this->primaryKey = $params['primary_key'] ?? 'id'; |
| 34 | - } |
|
| 35 | - /** |
|
| 36 | - * [load description] |
|
| 37 | - * @date 2019-11-02 |
|
| 38 | - * @return RefactorCI [description] |
|
| 39 | - */ |
|
| 40 | - public function load($class):RefactorCI |
|
| 41 | - { |
|
| 34 | + } |
|
| 35 | + /** |
|
| 36 | + * [load description] |
|
| 37 | + * @date 2019-11-02 |
|
| 38 | + * @return RefactorCI [description] |
|
| 39 | + */ |
|
| 40 | + public function load($class):RefactorCI |
|
| 41 | + { |
|
| 42 | 42 | include APPPATH.'libraries/refactor/'.$class.'.php'; |
| 43 | 43 | return $this; |
| 44 | - } |
|
| 45 | - /** |
|
| 46 | - * [payload description] |
|
| 47 | - * @date 2019-11-02 |
|
| 48 | - * @param string $class [description] |
|
| 49 | - * @param [type] $object [description] |
|
| 50 | - * @return [type] [description] |
|
| 51 | - */ |
|
| 52 | - public function payload(string $class, $object) |
|
| 53 | - { |
|
| 44 | + } |
|
| 45 | + /** |
|
| 46 | + * [payload description] |
|
| 47 | + * @date 2019-11-02 |
|
| 48 | + * @param string $class [description] |
|
| 49 | + * @param [type] $object [description] |
|
| 50 | + * @return [type] [description] |
|
| 51 | + */ |
|
| 52 | + public function payload(string $class, $object) |
|
| 53 | + { |
|
| 54 | 54 | return (new $class($object))->toArray(); |
| 55 | - } |
|
| 56 | - /** |
|
| 57 | - * [array description] |
|
| 58 | - * @date 2019-11-02 |
|
| 59 | - * @param string $class [description] |
|
| 60 | - * @param array $array [description] |
|
| 61 | - * @return array [description] |
|
| 62 | - */ |
|
| 63 | - public function array(string $class, array $array):array |
|
| 64 | - { |
|
| 55 | + } |
|
| 56 | + /** |
|
| 57 | + * [array description] |
|
| 58 | + * @date 2019-11-02 |
|
| 59 | + * @param string $class [description] |
|
| 60 | + * @param array $array [description] |
|
| 61 | + * @return array [description] |
|
| 62 | + */ |
|
| 63 | + public function array(string $class, array $array):array |
|
| 64 | + { |
|
| 65 | 65 | $refactor = new $class(); |
| 66 | 66 | $buff; |
| 67 | 67 | for ($x = 0; $x < count($array); $x++) { |
| 68 | - $refactor->switchPayload($array[$x]); |
|
| 69 | - $buff = $refactor->toArray(); |
|
| 70 | - if ($buff != null) $array[$x] = $buff; |
|
| 68 | + $refactor->switchPayload($array[$x]); |
|
| 69 | + $buff = $refactor->toArray(); |
|
| 70 | + if ($buff != null) $array[$x] = $buff; |
|
| 71 | 71 | } |
| 72 | 72 | return $array; |
| 73 | - } |
|
| 74 | - /** |
|
| 75 | - * [run description] |
|
| 76 | - * @param array|string $object [description] |
|
| 77 | - * @param string $ruleName [description] |
|
| 78 | - */ |
|
| 79 | - function run(array &$object, $ruleName):void |
|
| 80 | - { |
|
| 73 | + } |
|
| 74 | + /** |
|
| 75 | + * [run description] |
|
| 76 | + * @param array|string $object [description] |
|
| 77 | + * @param string $ruleName [description] |
|
| 78 | + */ |
|
| 79 | + function run(array &$object, $ruleName):void |
|
| 80 | + { |
|
| 81 | 81 | if ($object == null) return; |
| 82 | 82 | // Reolve Rules. |
| 83 | 83 | if (is_scalar($ruleName)) { |
| 84 | - $rule = $this->ci->config->item("refactor_$ruleName"); |
|
| 84 | + $rule = $this->ci->config->item("refactor_$ruleName"); |
|
| 85 | 85 | } else { |
| 86 | - // Rule was probablt passed in as an array (associative) and we support |
|
| 87 | - // that. |
|
| 88 | - $rule = is_array($ruleName) ? $ruleName : null; |
|
| 86 | + // Rule was probablt passed in as an array (associative) and we support |
|
| 87 | + // that. |
|
| 88 | + $rule = is_array($ruleName) ? $ruleName : null; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | if ($rule == null) return; // No need to go further as rule doesn't exist. |
| 92 | 92 | // Keep |
| 93 | 93 | if (isset($rule['keep'])) { |
| 94 | - $keys = array_keys($object); |
|
| 95 | - for ($x = 0; $x < count($object); $x++) { |
|
| 94 | + $keys = array_keys($object); |
|
| 95 | + for ($x = 0; $x < count($object); $x++) { |
|
| 96 | 96 | if (!in_array($keys[$X], $rule['keep'])) { |
| 97 | - unset($object[$keys[$x]]); |
|
| 97 | + unset($object[$keys[$x]]); |
|
| 98 | + } |
|
| 98 | 99 | } |
| 99 | - } |
|
| 100 | 100 | } |
| 101 | 101 | // Unset |
| 102 | 102 | if (isset($rule['unset'])) { |
| 103 | - $this->unset_values($object, $rule); |
|
| 103 | + $this->unset_values($object, $rule); |
|
| 104 | 104 | } |
| 105 | 105 | // Replace |
| 106 | 106 | if (isset($rule['replace'])) { |
| 107 | - $this->replace_fields($object, $rule); |
|
| 107 | + $this->replace_fields($object, $rule); |
|
| 108 | 108 | } |
| 109 | 109 | // Bools |
| 110 | 110 | if (isset($rule['bools'])) { |
| 111 | - foreach($rule['bools'] as $boolKey) { |
|
| 111 | + foreach($rule['bools'] as $boolKey) { |
|
| 112 | 112 | $object[$boolKey] = $object[$boolKey] == 1 || $object[$boolKey] == 'true'; |
| 113 | - } |
|
| 113 | + } |
|
| 114 | 114 | } |
| 115 | 115 | // Cast |
| 116 | 116 | if (isset($rule['cast'])) { |
| 117 | - $this->cast_fields($object, $rule); |
|
| 117 | + $this->cast_fields($object, $rule); |
|
| 118 | 118 | } |
| 119 | 119 | // Inflate |
| 120 | 120 | if (isset($rule['inflate'])) { |
| 121 | - foreach($rule['inflate'] as $field => $data) { |
|
| 121 | + foreach($rule['inflate'] as $field => $data) { |
|
| 122 | 122 | $ids = json_decode($object[$field], true); |
| 123 | 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) { |
|
| 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 | 128 | $object[$field] = json_encode (json_decode ("{}")); |
| 129 | 129 | continue; |
| 130 | - } |
|
| 131 | - $object[$field] = $query->result_array()[0]; |
|
| 132 | - if (isset($data['refactor'])) $this->run($object[$field], $data['refactor']); |
|
| 133 | - continue; |
|
| 130 | + } |
|
| 131 | + $object[$field] = $query->result_array()[0]; |
|
| 132 | + if (isset($data['refactor'])) $this->run($object[$field], $data['refactor']); |
|
| 133 | + continue; |
|
| 134 | 134 | } |
| 135 | 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])) { |
|
| 136 | + if ($ids == null) return; |
|
| 137 | + $object[$field] = $ids; |
|
| 138 | + $this->ci->jsonp->parse($object[$field]); |
|
| 139 | + if (is_array($object[$field])) { |
|
| 140 | 140 | $refs = $this->ci->jsonp->get_reference($data['path']); |
| 141 | 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']); |
|
| 142 | + $refs[$x] = $this->inflate_value($data['table'], $refs[$x]); |
|
| 143 | + // Recursion |
|
| 144 | + if (isset($data['refactor'])) $this->run($refs[$x], $data['refactor']); |
|
| 145 | 145 | } |
| 146 | - } else { |
|
| 146 | + } else { |
|
| 147 | 147 | $this->ci->jsonp->set($data['path'], $this->inflate_value($data['table'], $ids)); |
| 148 | 148 | // Recursion |
| 149 | 149 | if (isset($data['refactor'])) $this->run($this->ci->jsonp->get_reference($data['path']), $data['refactor']); |
| 150 | - } |
|
| 151 | - return; |
|
| 150 | + } |
|
| 151 | + return; |
|
| 152 | 152 | } |
| 153 | 153 | $object[$field] = []; |
| 154 | 154 | if ($ids == null) return; |
| 155 | 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) { |
|
| 156 | + $this->ci->db->where($this->primaryKey, $id); |
|
| 157 | + $query = $this->ci->db->get($data['table']); |
|
| 158 | + if ($query->num_rows() == 0) { |
|
| 159 | 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']); |
|
| 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 | + } |
|
| 164 | 165 | } |
| 165 | - } |
|
| 166 | 166 | } |
| 167 | - } |
|
| 168 | - private function inflate_value(string $table, $value) |
|
| 169 | - { |
|
| 167 | + } |
|
| 168 | + private function inflate_value(string $table, $value) |
|
| 169 | + { |
|
| 170 | 170 | $this->ci->db->where($this->primaryKey, $value); |
| 171 | 171 | $query = $this->ci->db->get($table); |
| 172 | 172 | return $query->num_rows() > 0 ? $query->result_array()[0] : null; |
| 173 | - } |
|
| 174 | - /** |
|
| 175 | - * [unset_values description] |
|
| 176 | - * @param array $object Object to Refactor. |
|
| 177 | - * @param array $rule Rule data, containing keys to unset in the given |
|
| 178 | - * associative array. |
|
| 179 | - */ |
|
| 180 | - private function unset_values(array &$object, &$rule):void { |
|
| 173 | + } |
|
| 174 | + /** |
|
| 175 | + * [unset_values description] |
|
| 176 | + * @param array $object Object to Refactor. |
|
| 177 | + * @param array $rule Rule data, containing keys to unset in the given |
|
| 178 | + * associative array. |
|
| 179 | + */ |
|
| 180 | + private function unset_values(array &$object, &$rule):void { |
|
| 181 | 181 | foreach($rule['unset'] as $key) { |
| 182 | - unset($object[$key]); |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - /** |
|
| 186 | - * [replace_fields description] |
|
| 187 | - * @param array $object [description] |
|
| 188 | - * @param [type] $rule [description] |
|
| 189 | - */ |
|
| 190 | - private function replace_fields(array &$object, &$rule):void |
|
| 191 | - { |
|
| 182 | + unset($object[$key]); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + /** |
|
| 186 | + * [replace_fields description] |
|
| 187 | + * @param array $object [description] |
|
| 188 | + * @param [type] $rule [description] |
|
| 189 | + */ |
|
| 190 | + private function replace_fields(array &$object, &$rule):void |
|
| 191 | + { |
|
| 192 | 192 | foreach ($rule['replace'] as $oldKey => $newKey) { |
| 193 | - $object[$newKey] = $object[$oldKey]; |
|
| 194 | - unset($object[$oldKey]); |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - /** |
|
| 198 | - * [cast_fields description] |
|
| 199 | - * @param array $object [description] |
|
| 200 | - * @param [type] $rule [description] |
|
| 201 | - */ |
|
| 202 | - private function cast_fields(array &$object, &$rule):void |
|
| 203 | - { |
|
| 193 | + $object[$newKey] = $object[$oldKey]; |
|
| 194 | + unset($object[$oldKey]); |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + /** |
|
| 198 | + * [cast_fields description] |
|
| 199 | + * @param array $object [description] |
|
| 200 | + * @param [type] $rule [description] |
|
| 201 | + */ |
|
| 202 | + private function cast_fields(array &$object, &$rule):void |
|
| 203 | + { |
|
| 204 | 204 | foreach ($rule['cast'] as $key => $type) { |
| 205 | - switch ($type) { |
|
| 205 | + switch ($type) { |
|
| 206 | 206 | case 'int': |
| 207 | 207 | $object[$key] = (int) $object[$key]; |
| 208 | - break; |
|
| 208 | + break; |
|
| 209 | 209 | case 'string': |
| 210 | 210 | $object[$key] = (string) $object[$key]; |
| 211 | - break; |
|
| 212 | - } |
|
| 211 | + break; |
|
| 212 | + } |
|
| 213 | + } |
|
| 213 | 214 | } |
| 214 | - } |
|
| 215 | 215 | } |
| 216 | 216 | ?> |
@@ -15,9 +15,9 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | private $primaryKey; |
| 17 | 17 | |
| 18 | - function __construct($params=null) |
|
| 18 | + function __construct($params = null) |
|
| 19 | 19 | { |
| 20 | - $this->ci =& get_instance(); |
|
| 20 | + $this->ci = & get_instance(); |
|
| 21 | 21 | $this->ci->load->config("refactor", false, true); |
| 22 | 22 | $this->ci->load->splint('francis94c/jsonp', '+JSONP', null, 'jsonp'); |
| 23 | 23 | require_once('RefactorPayload.php'); |
@@ -108,24 +108,24 @@ discard block |
||
| 108 | 108 | } |
| 109 | 109 | // Bools |
| 110 | 110 | if (isset($rule['bools'])) { |
| 111 | - foreach($rule['bools'] as $boolKey) { |
|
| 111 | + foreach ($rule['bools'] as $boolKey) { |
|
| 112 | 112 | $object[$boolKey] = $object[$boolKey] == 1 || $object[$boolKey] == 'true'; |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | // Cast |
| 116 | - if (isset($rule['cast'])) { |
|
| 116 | + if (isset($rule['cast'])) { |
|
| 117 | 117 | $this->cast_fields($object, $rule); |
| 118 | 118 | } |
| 119 | 119 | // Inflate |
| 120 | 120 | if (isset($rule['inflate'])) { |
| 121 | - foreach($rule['inflate'] as $field => $data) { |
|
| 121 | + foreach ($rule['inflate'] as $field => $data) { |
|
| 122 | 122 | $ids = json_decode($object[$field], true); |
| 123 | 123 | if (is_scalar($ids)) { |
| 124 | 124 | // JSON Array wasn't supplied. Let's treat it as a scaler ID. |
| 125 | 125 | $this->ci->db->where($this->primaryKey, $ids); |
| 126 | 126 | $query = $this->ci->db->get($data['table']); |
| 127 | 127 | if ($query->num_rows() == 0) { |
| 128 | - $object[$field] = json_encode (json_decode ("{}")); |
|
| 128 | + $object[$field] = json_encode(json_decode("{}")); |
|
| 129 | 129 | continue; |
| 130 | 130 | } |
| 131 | 131 | $object[$field] = $query->result_array()[0]; |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | } |
| 153 | 153 | $object[$field] = []; |
| 154 | 154 | if ($ids == null) return; |
| 155 | - foreach($ids as $id) { |
|
| 155 | + foreach ($ids as $id) { |
|
| 156 | 156 | $this->ci->db->where($this->primaryKey, $id); |
| 157 | 157 | $query = $this->ci->db->get($data['table']); |
| 158 | 158 | if ($query->num_rows() == 0) { |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * associative array. |
| 179 | 179 | */ |
| 180 | 180 | private function unset_values(array &$object, &$rule):void { |
| 181 | - foreach($rule['unset'] as $key) { |
|
| 181 | + foreach ($rule['unset'] as $key) { |
|
| 182 | 182 | unset($object[$key]); |
| 183 | 183 | } |
| 184 | 184 | } |
@@ -67,7 +67,9 @@ discard block |
||
| 67 | 67 | for ($x = 0; $x < count($array); $x++) { |
| 68 | 68 | $refactor->switchPayload($array[$x]); |
| 69 | 69 | $buff = $refactor->toArray(); |
| 70 | - if ($buff != null) $array[$x] = $buff; |
|
| 70 | + if ($buff != null) { |
|
| 71 | + $array[$x] = $buff; |
|
| 72 | + } |
|
| 71 | 73 | } |
| 72 | 74 | return $array; |
| 73 | 75 | } |
@@ -78,7 +80,9 @@ discard block |
||
| 78 | 80 | */ |
| 79 | 81 | function run(array &$object, $ruleName):void |
| 80 | 82 | { |
| 81 | - if ($object == null) return; |
|
| 83 | + if ($object == null) { |
|
| 84 | + return; |
|
| 85 | + } |
|
| 82 | 86 | // Reolve Rules. |
| 83 | 87 | if (is_scalar($ruleName)) { |
| 84 | 88 | $rule = $this->ci->config->item("refactor_$ruleName"); |
@@ -88,7 +92,10 @@ discard block |
||
| 88 | 92 | $rule = is_array($ruleName) ? $ruleName : null; |
| 89 | 93 | } |
| 90 | 94 | |
| 91 | - if ($rule == null) return; // No need to go further as rule doesn't exist. |
|
| 95 | + if ($rule == null) { |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + // No need to go further as rule doesn't exist. |
|
| 92 | 99 | // Keep |
| 93 | 100 | if (isset($rule['keep'])) { |
| 94 | 101 | $keys = array_keys($object); |
@@ -129,11 +136,15 @@ discard block |
||
| 129 | 136 | continue; |
| 130 | 137 | } |
| 131 | 138 | $object[$field] = $query->result_array()[0]; |
| 132 | - if (isset($data['refactor'])) $this->run($object[$field], $data['refactor']); |
|
| 139 | + if (isset($data['refactor'])) { |
|
| 140 | + $this->run($object[$field], $data['refactor']); |
|
| 141 | + } |
|
| 133 | 142 | continue; |
| 134 | 143 | } |
| 135 | 144 | if (isset($data['path'])) { |
| 136 | - if ($ids == null) return; |
|
| 145 | + if ($ids == null) { |
|
| 146 | + return; |
|
| 147 | + } |
|
| 137 | 148 | $object[$field] = $ids; |
| 138 | 149 | $this->ci->jsonp->parse($object[$field]); |
| 139 | 150 | if (is_array($object[$field])) { |
@@ -141,17 +152,23 @@ discard block |
||
| 141 | 152 | for ($x = 0; $x < count($refs); $x++) { |
| 142 | 153 | $refs[$x] = $this->inflate_value($data['table'], $refs[$x]); |
| 143 | 154 | // Recursion |
| 144 | - if (isset($data['refactor'])) $this->run($refs[$x], $data['refactor']); |
|
| 155 | + if (isset($data['refactor'])) { |
|
| 156 | + $this->run($refs[$x], $data['refactor']); |
|
| 157 | + } |
|
| 145 | 158 | } |
| 146 | 159 | } else { |
| 147 | 160 | $this->ci->jsonp->set($data['path'], $this->inflate_value($data['table'], $ids)); |
| 148 | 161 | // Recursion |
| 149 | - if (isset($data['refactor'])) $this->run($this->ci->jsonp->get_reference($data['path']), $data['refactor']); |
|
| 162 | + if (isset($data['refactor'])) { |
|
| 163 | + $this->run($this->ci->jsonp->get_reference($data['path']), $data['refactor']); |
|
| 164 | + } |
|
| 150 | 165 | } |
| 151 | 166 | return; |
| 152 | 167 | } |
| 153 | 168 | $object[$field] = []; |
| 154 | - if ($ids == null) return; |
|
| 169 | + if ($ids == null) { |
|
| 170 | + return; |
|
| 171 | + } |
|
| 155 | 172 | foreach($ids as $id) { |
| 156 | 173 | $this->ci->db->where($this->primaryKey, $id); |
| 157 | 174 | $query = $this->ci->db->get($data['table']); |
@@ -160,7 +177,9 @@ discard block |
||
| 160 | 177 | } |
| 161 | 178 | $object[$field][] = $query->result_array()[0]; |
| 162 | 179 | // Recursion |
| 163 | - if (isset($data['refactor'])) $this->run($object[$field][count($object[$field]) - 1], $data['refactor']); |
|
| 180 | + if (isset($data['refactor'])) { |
|
| 181 | + $this->run($object[$field][count($object[$field]) - 1], $data['refactor']); |
|
| 182 | + } |
|
| 164 | 183 | } |
| 165 | 184 | } |
| 166 | 185 | } |
@@ -5,81 +5,81 @@ |
||
| 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 | - * [setPayload description] |
|
| 58 | - * @date 2019-11-02 |
|
| 59 | - * @param [type] $payload [description] |
|
| 60 | - */ |
|
| 61 | - public function setPayload($payload):void |
|
| 62 | - { |
|
| 55 | + } |
|
| 56 | + /** |
|
| 57 | + * [setPayload description] |
|
| 58 | + * @date 2019-11-02 |
|
| 59 | + * @param [type] $payload [description] |
|
| 60 | + */ |
|
| 61 | + public function setPayload($payload):void |
|
| 62 | + { |
|
| 63 | 63 | $this->payload = $payload; |
| 64 | - } |
|
| 65 | - /** |
|
| 66 | - * [set_payload description] |
|
| 67 | - * @date 2019-11-02 |
|
| 68 | - * @param array $payload [description] |
|
| 69 | - */ |
|
| 70 | - public function switchPayload(&$payload):void |
|
| 71 | - { |
|
| 64 | + } |
|
| 65 | + /** |
|
| 66 | + * [set_payload description] |
|
| 67 | + * @date 2019-11-02 |
|
| 68 | + * @param array $payload [description] |
|
| 69 | + */ |
|
| 70 | + public function switchPayload(&$payload):void |
|
| 71 | + { |
|
| 72 | 72 | $this->payload =& $payload; |
| 73 | - } |
|
| 74 | - /** |
|
| 75 | - * [toArray description] |
|
| 76 | - * @date 2019-11-02 |
|
| 77 | - * @return array [description] |
|
| 78 | - */ |
|
| 79 | - public function toArray():array |
|
| 80 | - { |
|
| 73 | + } |
|
| 74 | + /** |
|
| 75 | + * [toArray description] |
|
| 76 | + * @date 2019-11-02 |
|
| 77 | + * @return array [description] |
|
| 78 | + */ |
|
| 79 | + public function toArray():array |
|
| 80 | + { |
|
| 81 | 81 | if (is_array($this->payload)) return $this->payload; |
| 82 | 82 | return json_decode(json_encode($this->payload), true); |
| 83 | - } |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | ?> |
@@ -11,7 +11,7 @@ discard block |
||
| 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 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public function switchPayload(&$payload):void |
| 71 | 71 | { |
| 72 | - $this->payload =& $payload; |
|
| 72 | + $this->payload = & $payload; |
|
| 73 | 73 | } |
| 74 | 74 | /** |
| 75 | 75 | * [toArray description] |
@@ -50,7 +50,9 @@ discard block |
||
| 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 | /** |
@@ -78,7 +80,9 @@ discard block |
||
| 78 | 80 | */ |
| 79 | 81 | public function toArray():array |
| 80 | 82 | { |
| 81 | - if (is_array($this->payload)) return $this->payload; |
|
| 83 | + if (is_array($this->payload)) { |
|
| 84 | + return $this->payload; |
|
| 85 | + } |
|
| 82 | 86 | return json_decode(json_encode($this->payload), true); |
| 83 | 87 | } |
| 84 | 88 | } |