Completed
Push — master ( 07f966...749888 )
by Ron
02:29
created
src/DiffStorageStore.php 1 patch
Spacing   +23 added lines, -23 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,11 +372,11 @@  discard block
 block discarded – undo
372 372
 	 */
373 373
 	private function formatKeyValuePairs($keyValues) {
374 374
 		$keyParts = [];
375
-		foreach($keyValues as $key => $value) {
376
-			if(is_string($value)) {
375
+		foreach ($keyValues as $key => $value) {
376
+			if (is_string($value)) {
377 377
 				$value = preg_replace('/\\s+/', ' ', $value);
378
-				if(strlen($value) > 20) {
379
-					$value = substr($value, 0, 16) . ' ...';
378
+				if (strlen($value) > 20) {
379
+					$value = substr($value, 0, 16).' ...';
380 380
 				}
381 381
 			}
382 382
 			$keyParts[] = sprintf("%s: %s", $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
Please login to merge, or discard this patch.