Code Duplication    Length = 29-31 lines in 2 locations

src/DataSource/DoctrineDataSource.php 1 location

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

src/DataSource/NetteDatabaseTableDataSource.php 1 location

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