Completed
Push — master ( 574567...ef1817 )
by Ron
02:25
created
src/DiffStorageStoreRowData.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -77,12 +77,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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,16 +105,16 @@  discard block
 block discarded – undo
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
-			$formatVal = function ($value) {
110
+			$formatVal = function($value) {
111 111
 				$value = preg_replace('/\\s+/', ' ', $value);
112
-				if(strlen($value) > 20) {
113
-					$value = substr($value, 0, 16) . ' ...';
112
+				if (strlen($value) > 20) {
113
+					$value = substr($value, 0, 16).' ...';
114 114
 				}
115 115
 				return $value;
116 116
 			};
117
-			foreach($diff as $fieldName => $values) {
117
+			foreach ($diff as $fieldName => $values) {
118 118
 				$foreignValue = $formatVal($values['foreign']);
119 119
 				$localValue = $formatVal($values['local']);
120 120
 				$result[] = sprintf("%s: %s -> %s", $fieldName, $foreignValue, $localValue);
@@ -130,13 +130,13 @@  discard block
 block discarded – undo
130 130
 	 * @return array
131 131
 	 */
132 132
 	private function applyOptions(array $row, array $options) {
133
-		if(count($options) < 1) {
133
+		if (count($options) < 1) {
134 134
 			return $row;
135 135
 		}
136
-		if(array_key_exists('keys', $options) && is_array($options['keys'])) {
136
+		if (array_key_exists('keys', $options) && is_array($options['keys'])) {
137 137
 			$row = array_intersect_key($row, array_combine($options['keys'], $options['keys']));
138 138
 		}
139
-		if(array_key_exists('ignore', $options) && is_array($options['ignore'])) {
139
+		if (array_key_exists('ignore', $options) && is_array($options['ignore'])) {
140 140
 			$row = array_diff_key($row, array_combine($options['ignore'], $options['ignore']));
141 141
 		}
142 142
 		return $row;
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	 */
149 149
 	private function formatRow($row) {
150 150
 		$schema = $this->converter;
151
-		$schema = array_map(function () { return null; }, $schema);
151
+		$schema = array_map(function() { return null; }, $schema);
152 152
 		$row = array_merge($schema, $row);
153 153
 		return $row;
154 154
 	}
Please login to merge, or discard this patch.
src/DiffStorageStore.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function addRow(array $data, array $translation = null, $duplicateKeyHandler = null) {
66 66
 		$data = $this->translate($data, $translation);
67
-		if($duplicateKeyHandler === null) {
67
+		if ($duplicateKeyHandler === null) {
68 68
 			$duplicateKeyHandler = $this->duplicateKeyHandler;
69 69
 		}
70
-		$buildMetaData = function (array $data, array $keys) {
70
+		$buildMetaData = function(array $data, array $keys) {
71 71
 			$metaData = $data;
72 72
 			$metaData = array_diff_key($metaData, array_diff_key($metaData, $keys));
73 73
 			$metaData['___data'] = json_encode($data);
@@ -75,19 +75,19 @@  discard block
 block discarded – undo
75 75
 			return $metaData;
76 76
 		};
77 77
 		$metaData = $buildMetaData($data, $this->converter);
78
-		if($duplicateKeyHandler === null) {
78
+		if ($duplicateKeyHandler === null) {
79 79
 			$this->replaceStmt->execute($metaData);
80 80
 		} else {
81 81
 			try {
82 82
 				$this->insertStmt->execute($metaData);
83 83
 			} catch (\PDOException $e) {
84
-				if(strpos($e->getMessage(), 'UNIQUE constraint failed') !== false) {
84
+				if (strpos($e->getMessage(), 'UNIQUE constraint failed') !== false) {
85 85
 					$metaData = $buildMetaData($data, $this->converter);
86 86
 					unset($metaData['___data']);
87 87
 					unset($metaData['___sort']);
88 88
 					$this->selectStmt->execute($metaData);
89 89
 					$oldData = $this->selectStmt->fetch(PDO::FETCH_COLUMN, 0);
90
-					if($oldData === null) {
90
+					if ($oldData === null) {
91 91
 						$oldData = [];
92 92
 					} else {
93 93
 						$oldData = json_decode($oldData, true);
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 * @return $this
111 111
 	 */
112 112
 	public function addRows($rows, array $translation = null, $duplicateKeyHandler = null) {
113
-		foreach($rows as $row) {
113
+		foreach ($rows as $row) {
114 114
 			$this->addRow($row, $translation, $duplicateKeyHandler);
115 115
 		}
116 116
 		return $this;
@@ -121,11 +121,11 @@  discard block
 block discarded – undo
121 121
 	 */
122 122
 	public function hasAnyChanges() {
123 123
 		/** @noinspection PhpUnusedLocalVariableInspection */
124
-		foreach($this->getNewOrChanged() as $_) {
124
+		foreach ($this->getNewOrChanged() as $_) {
125 125
 			return true;
126 126
 		}
127 127
 		/** @noinspection PhpUnusedLocalVariableInspection */
128
-		foreach($this->getMissing() as $_) {
128
+		foreach ($this->getMissing() as $_) {
129 129
 			return true;
130 130
 		}
131 131
 		return false;
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 				s2.s_ab IS NULL
153 153
 			ORDER BY
154 154
 				s1.s_sort
155
-		', function (DiffStorageStoreRowInterface $row) {
155
+		', function(DiffStorageStoreRowInterface $row) {
156 156
 			return $this->formatNewRow($row);
157 157
 		});
158 158
 	}
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 				s1.s_value != s2.s_value
179 179
 			ORDER BY
180 180
 				s1.s_sort
181
-		', function (DiffStorageStoreRowInterface $row) {
181
+		', function(DiffStorageStoreRowInterface $row) {
182 182
 			return $this->formatChangedRow($row);
183 183
 		});
184 184
 	}
@@ -202,8 +202,8 @@  discard block
 block discarded – undo
202 202
 				((s2.s_ab IS NULL) OR (s1.s_value != s2.s_value))
203 203
 			ORDER BY
204 204
 				s1.s_sort
205
-		', function (DiffStorageStoreRowInterface $row) {
206
-			if(count($row->getForeign()->getValueData())) {
205
+		', function(DiffStorageStoreRowInterface $row) {
206
+			if (count($row->getForeign()->getValueData())) {
207 207
 				return $this->formatChangedRow($row);
208 208
 			} else {
209 209
 				return $this->formatNewRow($row);
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 				s2.s_ab IS NULL
233 233
 			ORDER BY
234 234
 				s1.s_sort
235
-		', function (DiffStorageStoreRowInterface $row) {
235
+		', function(DiffStorageStoreRowInterface $row) {
236 236
 			return $this->formatMissingRow($row);
237 237
 		});
238 238
 	}
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 	private function query($query, $stringFormatter) {
255 255
 		$stmt = $this->pdo->query($query);
256 256
 		$stmt->execute(['sA' => $this->storeA, 'sB' => $this->storeB]);
257
-		while($row = $stmt->fetch(PDO::FETCH_NUM)) {
257
+		while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
258 258
 			$d = json_decode($row[1], true);
259 259
 			$f = json_decode($row[2], true);
260 260
 			yield $this->instantiateRow($d, $f, $stringFormatter);
@@ -278,9 +278,9 @@  discard block
 block discarded – undo
278 278
 		';
279 279
 		$stmt = $this->pdo->query($query);
280 280
 		$stmt->execute(['s' => $this->storeA]);
281
-		while($row = $stmt->fetch(PDO::FETCH_NUM)) {
281
+		while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
282 282
 			$row = json_decode($row[0], true);
283
-			$row = $this->instantiateRow($row, [], function (DiffStorageStoreRowInterface $row) {
283
+			$row = $this->instantiateRow($row, [], function(DiffStorageStoreRowInterface $row) {
284 284
 				return $this->formatKeyValuePairs($row->getData());
285 285
 			});
286 286
 			yield $row->getData();
@@ -294,10 +294,10 @@  discard block
 block discarded – undo
294 294
 	 * @return array
295 295
 	 */
296 296
 	private function translate(array $data, array $translation = null) {
297
-		if($translation !== null) {
297
+		if ($translation !== null) {
298 298
 			$result = [];
299
-			foreach($data as $key => $value) {
300
-				if(array_key_exists($key, $translation)) {
299
+			foreach ($data as $key => $value) {
300
+				if (array_key_exists($key, $translation)) {
301 301
 					$key = $translation[$key];
302 302
 				}
303 303
 				$result[$key] = $value;
@@ -372,10 +372,10 @@  discard block
 block discarded – undo
372 372
 	 */
373 373
 	private function formatKeyValuePairs($keyValues) {
374 374
 		$keyParts = [];
375
-		foreach($keyValues as $key => $value) {
375
+		foreach ($keyValues as $key => $value) {
376 376
 			$value = preg_replace('/\\s+/', ' ', $value);
377
-			if(strlen($value) > 20) {
378
-				$value = substr($value, 0, 16) . ' ...';
377
+			if (strlen($value) > 20) {
378
+				$value = substr($value, 0, 16).' ...';
379 379
 			}
380 380
 			$keyParts[] = sprintf("%s: %s", $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
381 381
 		}
Please login to merge, or discard this patch.