Code Duplication    Length = 29-31 lines in 2 locations

src/DataSource/DoctrineDataSource.php 1 location

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

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