Code Duplication    Length = 29-31 lines in 2 locations

src/DataSource/NetteDatabaseTableDataSource.php 1 location

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

src/DataSource/DoctrineDataSource.php 1 location

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