Code Duplication    Length = 29-31 lines in 2 locations

src/DataSource/NetteDatabaseTableDataSource.php 1 location

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

src/DataSource/DoctrineDataSource.php 1 location

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