@@ -19,9 +19,9 @@ discard block |
||
| 19 | 19 | * @param array $converter |
| 20 | 20 | */ |
| 21 | 21 | public function __construct(array $localData = null, array $foreignData = null, array $keys, array $valueKeys, array $converter) { |
| 22 | - if($localData !== null) { |
|
| 22 | + if ($localData !== null) { |
|
| 23 | 23 | $this->data = $localData; |
| 24 | - } elseif($foreignData !== null) { |
|
| 24 | + } elseif ($foreignData !== null) { |
|
| 25 | 25 | $this->data = $foreignData; |
| 26 | 26 | } |
| 27 | 27 | $localData = is_array($localData) ? $localData : []; |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * @return mixed |
| 107 | 107 | */ |
| 108 | 108 | public function offsetGet($offset) { |
| 109 | - if($this->offsetExists($offset)) { |
|
| 109 | + if ($this->offsetExists($offset)) { |
|
| 110 | 110 | return $this->data[$offset]; |
| 111 | 111 | } |
| 112 | 112 | return null; |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * @return void |
| 127 | 127 | */ |
| 128 | 128 | public function offsetUnset($offset) { |
| 129 | - if($this->offsetExists($offset)) { |
|
| 129 | + if ($this->offsetExists($offset)) { |
|
| 130 | 130 | unset($this->data[$offset]); |
| 131 | 131 | } |
| 132 | 132 | } |
@@ -77,12 +77,12 @@ discard block |
||
| 77 | 77 | $keys = array_keys(array_merge($this->row, $this->foreignRow)); |
| 78 | 78 | $formattedLocalRow = $this->formatRow($localRow); |
| 79 | 79 | $formattedForeignRow = $this->formatRow($foreignRow); |
| 80 | - foreach($keys as $key) { |
|
| 81 | - $conv = function (array $row) use ($key) { |
|
| 80 | + foreach ($keys as $key) { |
|
| 81 | + $conv = function(array $row) use ($key) { |
|
| 82 | 82 | $value = null; |
| 83 | - if(array_key_exists($key, $row)) { |
|
| 83 | + if (array_key_exists($key, $row)) { |
|
| 84 | 84 | $value = $row[$key]; |
| 85 | - if(array_key_exists($key, $this->converter)) { |
|
| 85 | + if (array_key_exists($key, $this->converter)) { |
|
| 86 | 86 | $value = call_user_func($this->converter[$key], $value); |
| 87 | 87 | } |
| 88 | 88 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | }; |
| 91 | 91 | $localValue = call_user_func($conv, $formattedLocalRow); |
| 92 | 92 | $foreignValue = call_user_func($conv, $formattedForeignRow); |
| 93 | - if(json_encode($localValue) !== json_encode($foreignValue)) { |
|
| 93 | + if (json_encode($localValue) !== json_encode($foreignValue)) { |
|
| 94 | 94 | $diff[$key] = ['local' => $localValue, 'foreign' => $foreignValue]; |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -105,9 +105,9 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | public function getDiffFormatted(array $fields = null, $format = null) { |
| 107 | 107 | $diff = $this->getDiff($fields); |
| 108 | - if($format === null) { |
|
| 108 | + if ($format === null) { |
|
| 109 | 109 | $result = []; |
| 110 | - foreach($diff as $fieldName => $values) { |
|
| 110 | + foreach ($diff as $fieldName => $values) { |
|
| 111 | 111 | $result[] = sprintf("%s: %s -> %s", $fieldName, $values['foreign'], $values['local']); |
| 112 | 112 | } |
| 113 | 113 | return join(', ', $result); |
@@ -121,13 +121,13 @@ discard block |
||
| 121 | 121 | * @return array |
| 122 | 122 | */ |
| 123 | 123 | private function applyOptions(array $row, array $options) { |
| 124 | - if(count($options) < 1) { |
|
| 124 | + if (count($options) < 1) { |
|
| 125 | 125 | return $row; |
| 126 | 126 | } |
| 127 | - if(array_key_exists('keys', $options)) { |
|
| 127 | + if (array_key_exists('keys', $options)) { |
|
| 128 | 128 | $row = array_intersect_key($row, array_combine($options['keys'], $options['keys'])); |
| 129 | 129 | } |
| 130 | - if(array_key_exists('ignore', $options)) { |
|
| 130 | + if (array_key_exists('ignore', $options)) { |
|
| 131 | 131 | $row = array_diff_key($row, array_combine($options['ignore'], $options['ignore'])); |
| 132 | 132 | } |
| 133 | 133 | return $row; |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | private function formatRow($row) { |
| 141 | 141 | $schema = $this->converter; |
| 142 | - $schema = array_map(function () { return null; }, $schema); |
|
| 142 | + $schema = array_map(function() { return null; }, $schema); |
|
| 143 | 143 | $row = array_merge($schema, $row); |
| 144 | 144 | return $row; |
| 145 | 145 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | private function buildSchema($schema) { |
| 84 | 84 | $def = []; |
| 85 | - foreach($schema as $name => $type) { |
|
| 85 | + foreach ($schema as $name => $type) { |
|
| 86 | 86 | switch ($type) { |
| 87 | 87 | case 'BOOL': |
| 88 | 88 | $def[] = sprintf('CASE WHEN CAST(:'.$name.' AS INT) = 0 THEN \'false\' ELSE \'true\' END'); |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | break; |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | - if(!count($def)) { |
|
| 110 | + if (!count($def)) { |
|
| 111 | 111 | throw new EmptySchemaException('Can\'t operate with empty schema'); |
| 112 | 112 | } |
| 113 | 113 | return join('||"|"||', $def); |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | private function buildConverter($schema) { |
| 122 | 122 | $def = []; |
| 123 | - foreach($schema as $name => $type) { |
|
| 123 | + foreach ($schema as $name => $type) { |
|
| 124 | 124 | switch ($type) { |
| 125 | 125 | case 'BOOL': |
| 126 | 126 | $def[$name] = 'boolval'; |
@@ -129,19 +129,19 @@ discard block |
||
| 129 | 129 | $def[$name] = 'intval'; |
| 130 | 130 | break; |
| 131 | 131 | case 'FLOAT': |
| 132 | - $def[$name] = function ($value) { return number_format($value, 6, '.', ''); }; |
|
| 132 | + $def[$name] = function($value) { return number_format($value, 6, '.', ''); }; |
|
| 133 | 133 | break; |
| 134 | 134 | case 'DOUBLE': |
| 135 | - $def[$name] = function ($value) { return number_format($value, 12, '.', ''); }; |
|
| 135 | + $def[$name] = function($value) { return number_format($value, 12, '.', ''); }; |
|
| 136 | 136 | break; |
| 137 | 137 | case 'MONEY': |
| 138 | - $def[$name] = function ($value) { return number_format($value, 2, '.', ''); }; |
|
| 138 | + $def[$name] = function($value) { return number_format($value, 2, '.', ''); }; |
|
| 139 | 139 | break; |
| 140 | 140 | case 'STRING': |
| 141 | - $def[$name] = function ($value) { return (string) $value; }; |
|
| 141 | + $def[$name] = function($value) { return (string) $value; }; |
|
| 142 | 142 | break; |
| 143 | 143 | case 'MD5': |
| 144 | - $def[$name] = function ($value) { return md5((string) $value); }; |
|
| 144 | + $def[$name] = function($value) { return md5((string) $value); }; |
|
| 145 | 145 | break; |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -151,11 +151,11 @@ discard block |
||
| 151 | 151 | /** |
| 152 | 152 | */ |
| 153 | 153 | private function compatibility() { |
| 154 | - if(!$this->testStatement('SELECT printf("%0.2f", 19.99999) AS res')) { |
|
| 154 | + if (!$this->testStatement('SELECT printf("%0.2f", 19.99999) AS res')) { |
|
| 155 | 155 | $this->registerUDFunction('printf', 'sprintf'); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if(!$this->testStatement('SELECT md5("aaa") AS md5res')) { |
|
| 158 | + if (!$this->testStatement('SELECT md5("aaa") AS md5res')) { |
|
| 159 | 159 | $this->registerUDFunction('md5', 'md5'); |
| 160 | 160 | } |
| 161 | 161 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * @throws Exception |
| 179 | 179 | */ |
| 180 | 180 | private function registerUDFunction($name, $callback) { |
| 181 | - if(!method_exists($this->pdo, 'sqliteCreateFunction')) { |
|
| 181 | + if (!method_exists($this->pdo, 'sqliteCreateFunction')) { |
|
| 182 | 182 | throw new Exception('It is not possible to create user defined functions for rkr/data-diff\'s sqlite instance'); |
| 183 | 183 | } |
| 184 | 184 | call_user_func([$this->pdo, 'sqliteCreateFunction'], $name, $callback); |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | /** |
| 188 | 188 | */ |
| 189 | 189 | private function initSqlite() { |
| 190 | - $tryThis = function ($query) { |
|
| 190 | + $tryThis = function($query) { |
|
| 191 | 191 | try { |
| 192 | 192 | $this->pdo->exec($query); |
| 193 | 193 | } catch (Exception $e) { |
@@ -213,11 +213,11 @@ discard block |
||
| 213 | 213 | * @return array |
| 214 | 214 | */ |
| 215 | 215 | private function defineOptionDefaults($options) { |
| 216 | - if(!array_key_exists('dsn', $options)) { |
|
| 216 | + if (!array_key_exists('dsn', $options)) { |
|
| 217 | 217 | $options['dsn'] = 'sqlite::memory:'; |
| 218 | 218 | } |
| 219 | - if(!array_key_exists('duplicate_key_handler', $options)) { |
|
| 220 | - $options['duplicate_key_handler'] = function (array $newData = null, array $oldData = null) { |
|
| 219 | + if (!array_key_exists('duplicate_key_handler', $options)) { |
|
| 220 | + $options['duplicate_key_handler'] = function(array $newData = null, array $oldData = null) { |
|
| 221 | 221 | return array_merge($oldData, $newData); |
| 222 | 222 | }; |
| 223 | 223 | } |