Completed
Push — master ( 43c72a...f32624 )
by Peter
05:47
created

FinderEvents   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
lcom 0
cbo 1
dl 0
loc 58
ccs 18
cts 21
cp 0.8571
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A afterCount() 0 4 1
A afterExists() 0 4 1
A afterFind() 0 4 1
A beforeCount() 0 8 2
A beforeExists() 0 8 2
A beforeFind() 0 8 2
1
<?php
2
3
namespace Maslosoft\Mangan\Helpers;
4
5
use Maslosoft\Mangan\Events\Event;
6
use Maslosoft\Mangan\Interfaces\FinderInterface;
7
8
/**
9
 * FinderEvents
10
 *
11
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
12
 */
13
class FinderEvents
14
{
15
16 19
	public static function afterCount($model)
17
	{
18 19
		Event::trigger($model, FinderInterface::EventAfterCount);
19 19
	}
20
21 9
	public static function afterExists($model)
22
	{
23 9
		Event::trigger($model, FinderInterface::EventAfterExists);
24 9
	}
25
26 58
	public static function afterFind($model)
27
	{
28 58
		Event::trigger($model, FinderInterface::EventAfterFind);
29 58
	}
30
31
	/**
32
	 * Trigger before count event
33
	 * @return boolean
34
	 */
35 19
	public static function beforeCount($model)
36
	{
37 19
		if (!Event::hasHandler($model, FinderInterface::EventBeforeCount))
38
		{
39 19
			return true;
40
		}
41
		return Event::handled($model, FinderInterface::EventBeforeCount);
42
	}
43
44
	/**
45
	 * Trigger before exists event
46
	 * @return boolean
47
	 */
48 9
	public static function beforeExists($model)
49
	{
50 9
		if (!Event::hasHandler($model, FinderInterface::EventBeforeExists))
51
		{
52 9
			return true;
53
		}
54
		return Event::handled($model, FinderInterface::EventBeforeExists);
55
	}
56
57
	/**
58
	 * Trigger before find event
59
	 * @return boolean
60
	 */
61 60
	public static function beforeFind($model)
62
	{
63 60
		if (!Event::hasHandler($model, FinderInterface::EventBeforeFind))
64
		{
65 60
			return true;
66
		}
67
		return Event::handled($model, FinderInterface::EventBeforeFind);
68
	}
69
70
}
71