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

FinderEvents::beforeCount()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
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