Completed
Push — master ( 144202...6a00f8 )
by Peter
11:59
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 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 36
ccs 7
cts 11
cp 0.6364
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSort() 0 9 2
A setSort() 0 6 1
getModel() 0 1 ?
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Maslosoft\Mangan\Traits;
10
11
use Maslosoft\Mangan\Interfaces\SortInterface;
12
use Maslosoft\Mangan\Sort;
13
14
/**
15
 * SortAwareTrait
16
 *
17
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
18
 */
19
trait SortAwareTrait
20
{
21
22
	/**
23
	 * @var SortInterface
24
	 */
25
	private $sort;
26
27
	/**
28
	 * Returns the sort object.
29
	 * @return Sort the sorting object. If this is false, it means the sorting is disabled.
30
	 */
31 1
	public function getSort()
32
	{
33 1
		if ($this->sort === null)
34 1
		{
35 1
			$this->sort = new Sort;
36 1
			$this->sort->setModel($this->getModel());
37 1
		}
38 1
		return $this->sort;
39
	}
40
41
	/**
42
	 * Set sort
43
	 * @param SortInterface $sort
44
	 * @return static
45
	 */
46
	public function setSort(SortInterface $sort)
47
	{
48
		$this->sort = $sort;
49
		$this->sort->setModel($this->getModel());
50
		return $this;
51
	}
52
53
	abstract public function getModel();
54
}
55