Code Duplication    Length = 29-31 lines in 2 locations

src/DataSource/DoctrineDataSource.php 1 location

@@ 307-335 (lines=29) @@
304
	 * @param  Sorting $sorting
305
	 * @return static
306
	 */
307
	public function sort(Sorting $sorting)
308
	{
309
		if (is_callable($sorting->getSortCallback())) {
310
			call_user_func(
311
				$sorting->getSortCallback(),
312
				$this->data_source,
313
				$sorting->getSort()
314
			);
315
316
			return $this;
317
		}
318
319
		$sort = $sorting->getSort();
320
321
		if (!empty($sort)) {
322
			foreach ($sort as $column => $order) {
323
				$this->data_source->addOrderBy($this->checkAliases($column), $order);
324
			}
325
		} else {
326
			/**
327
			 * Has the statement already a order by clause?
328
			 */
329
			if (!$this->data_source->getDQLPart('orderBy')) {
330
				$this->data_source->orderBy($this->checkAliases($this->primary_key));
331
			}
332
		}
333
334
		return $this;
335
	}
336
337
338
	/**

src/DataSource/NetteDatabaseTableDataSource.php 1 location

@@ 274-304 (lines=31) @@
271
	 * @param  Sorting $sorting
272
	 * @return static
273
	 */
274
	public function sort(Sorting $sorting)
275
	{
276
		if (is_callable($sorting->getSortCallback())) {
277
			call_user_func(
278
				$sorting->getSortCallback(),
279
				$this->data_source,
280
				$sorting->getSort()
281
			);
282
283
			return $this;
284
		}
285
286
		$sort = $sorting->getSort();
287
288
		if (!empty($sort)) {
289
			$this->data_source->getSqlBuilder()->setOrder([], []);
290
291
			foreach ($sort as $column => $order) {
292
				$this->data_source->order("$column $order");
293
			}
294
		} else {
295
			/**
296
			 * Has the statement already a order by clause?
297
			 */
298
			if (!$this->data_source->getSqlBuilder()->getOrder()) {
299
				$this->data_source->order($this->primary_key);
300
			}
301
		}
302
303
		return $this;
304
	}
305
306
307
	/**