Completed
Push — master ( c8f19a...ddbfd2 )
by Peter
72:09 queued 69:12
created

SortAwareTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 63.64%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 36
ccs 7
cts 11
cp 0.6364
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setSort() 0 6 1
getModel() 0 1 ?
A getSort() 0 9 2
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL or Commercial license.
5
 *
6
 * @package maslosoft/mangan
7
 * @licence AGPL or Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]>
9
 * @copyright Copyright (c) Maslosoft
10
 * @copyright Copyright (c) Others as mentioned in code
11
 * @link https://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan\Traits;
15
16
use Maslosoft\Mangan\Interfaces\SortInterface;
17
use Maslosoft\Mangan\Sort;
18
19
/**
20
 * SortAwareTrait
21
 *
22
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
23
 */
24
trait SortAwareTrait
25
{
26
27
	/**
28
	 * @var SortInterface
29
	 */
30
	private $sort;
31
32
	/**
33
	 * Returns the sort object.
34
	 * @return Sort the sorting object. If this is false, it means the sorting is disabled.
35
	 */
36 4
	public function getSort()
37
	{
38 4
		if ($this->sort === null)
39 4
		{
40 4
			$this->sort = new Sort;
41 4
			$this->sort->setModel($this->getModel());
42 4
		}
43 4
		return $this->sort;
44
	}
45
46
	/**
47
	 * Set sort
48
	 * @param SortInterface $sort
49
	 * @return static
50
	 */
51
	public function setSort(SortInterface $sort)
52
	{
53
		$this->sort = $sort;
54
		$this->sort->setModel($this->getModel());
55
		return $this;
56
	}
57
58
	abstract public function getModel();
59
}
60