Code Duplication    Length = 29-31 lines in 2 locations

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
	/**

src/DataSource/DoctrineDataSource.php 1 location

@@ 324-352 (lines=29) @@
321
	 * @param  Sorting $sorting
322
	 * @return static
323
	 */
324
	public function sort(Sorting $sorting)
325
	{
326
		if (is_callable($sorting->getSortCallback())) {
327
			call_user_func(
328
				$sorting->getSortCallback(),
329
				$this->data_source,
330
				$sorting->getSort()
331
			);
332
333
			return $this;
334
		}
335
336
		$sort = $sorting->getSort();
337
338
		if (!empty($sort)) {
339
			foreach ($sort as $column => $order) {
340
				$this->data_source->addOrderBy($this->checkAliases($column), $order);
341
			}
342
		} else {
343
			/**
344
			 * Has the statement already a order by clause?
345
			 */
346
			if (!$this->data_source->getDQLPart('orderBy')) {
347
				$this->data_source->orderBy($this->checkAliases($this->primary_key));
348
			}
349
		}
350
351
		return $this;
352
	}
353
354
355
	/**