Completed
Push — master ( b4e9b7...cff413 )
by Peter
11:12
created

IndexManagerHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 26.67%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 26
ccs 4
cts 15
cp 0.2667
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 6 1
A setupHandlers() 0 16 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\Events\Handlers;
15
16
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
17
use Maslosoft\Mangan\EntityManager;
18
use Maslosoft\Mangan\Events\Event;
19
use Maslosoft\Mangan\Events\ModelEvent;
20
use Maslosoft\Mangan\Helpers\IndexManager;
21
use Maslosoft\Mangan\Interfaces\EventHandlersInterface;
22
use Maslosoft\Mangan\Interfaces\FinderInterface;
23
24
class IndexManagerHandler implements EventHandlersInterface
25
{
26
	public function setupHandlers()
27
	{
28
		$on = [
29
			EntityManager::EventBeforeInsert,
30
			EntityManager::EventBeforeSave,
31
			EntityManager::EventBeforeUpdate,
32
			FinderInterface::EventBeforeFind,
33
			FinderInterface::EventBeforeCount,
34
			FinderInterface::EventBeforeExists,
35
		];
36
		$handler = [$this, 'handle'];
37
		foreach ($on as $name)
38
		{
39
			Event::on(AnnotatedInterface::class, $name, $handler);
40
		}
41
	}
42
43 122
	public function handle(ModelEvent $e)
44
	{
45 122
		$e->isValid = true;
46 122
		IndexManager::fly()->create($e->sender);
47 122
		return true;
48
	}
49
}