Code Duplication    Length = 36-36 lines in 2 locations

src/Client.php 1 location

@@ 239-274 (lines=36) @@
236
	 * @param array $response Response data
237
	 * @return array Array with parsed data
238
	 */
239
	protected function parseResponse(array $response): array
240
	{
241
		$result = [];
242
		$i = -1;
243
		$lines = \count($response);
244
		foreach ($response as $key => $value) {
245
			switch ($value) {
246
			case '!re':
247
				$i++;
248
				break;
249
			case '!fatal':
250
				$result = $response;
251
				break 2;
252
			case '!trap':
253
			case '!done':
254
				// Check for =ret=, .tag and any other following messages
255
				for ($j = $key + 1; $j <= $lines; $j++) {
256
					// If we have lines after current one
257
					if (isset($response[$j])) {
258
						$this->pregResponse($response[$j], $matches);
259
						if (isset($matches[1][0], $matches[2][0])) {
260
							$result['after'][$matches[1][0]] = $matches[2][0];
261
						}
262
					}
263
				}
264
				break 2;
265
			default:
266
				$this->pregResponse($value, $matches);
267
				if (isset($matches[1][0], $matches[2][0])) {
268
					$result[$i][$matches[1][0]] = $matches[2][0];
269
				}
270
				break;
271
			}
272
		}
273
		return $result;
274
	}
275
276
	/**
277
	 * Parse result from RouterOS by regular expression

src/Iterators/ResponseIterator.php 1 location

@@ 106-141 (lines=36) @@
103
		$this->raw = [];
104
		$this->parsed = [];
105
	}
106
	private function parseResponse(array $response): array
107
	{
108
		$result = [];
109
		$i = -1;
110
		$lines = \count($response);
111
		foreach ($response as $key => $value) {
112
			switch ($value) {
113
			case '!re':
114
				$i++;
115
				break;
116
			case '!fatal':
117
				$result = $response;
118
				break 2;
119
			case '!trap':
120
			case '!done':
121
				// Check for =ret=, .tag and any other following messages
122
				for ($j = $key + 1; $j <= $lines; $j++) {
123
					// If we have lines after current one
124
					if (isset($response[$j])) {
125
						$this->pregResponse($response[$j], $matches);
126
						if (isset($matches[1][0], $matches[2][0])) {
127
							$result['after'][$matches[1][0]] = $matches[2][0];
128
						}
129
					}
130
				}
131
				break 2;
132
			default:
133
				$this->pregResponse($value, $matches);
134
				if (isset($matches[1][0], $matches[2][0])) {
135
					$result[$i][$matches[1][0]] = $matches[2][0];
136
				}
137
				break;
138
			}
139
		}
140
		return $result;
141
	}
142
	private function pregResponse(string $value, &$matches) {
143
		preg_match_all('/^[=|\.](.*)=(.*)/', $value, $matches);
144
	}