Completed
Push — master ( cff413...7f9d4c )
by Peter
07:00
created

UnknownDocumentType   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 37
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 4 1
A setData() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: peter
5
 * Date: 22.10.18
6
 * Time: 20:58
7
 */
8
9
namespace Maslosoft\Mangan\Events;
10
11
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
12
13
/**
14
 * Create event handler for this event
15
 * to try to recover from unknown document state.
16
 *
17
 * NOTE: Event *must* be handled for this to work.
18
 *
19
 * The handler can use `getData` to inspect what
20
 * was passed into `Transformator::toModel()` method,
21
 * adjust the data, or replace with completely new one and
22
 * pass it back to `setData`.
23
 *
24
 * Example use case:
25
 *
26
 * 1. Field was array of languages
27
 * 2. After application refactoring it was decided to change it to embedded array
28
 * 3. Old data exists containing only languages
29
 *
30
 * Solution:
31
 *
32
 * Event handler for UnknownDocumentType adds `_class` field and
33
 * set values properly.
34
 *
35
 * Class UnknownDocumentType
36
 * @package Maslosoft\Mangan\Events
37
 */
38
class UnknownDocumentType extends ModelEvent
39
{
40
	const EventName = 'unknownDocumentType';
41
	private $modelData = [];
42
43
	/**
44
	 * Parent Model
45
	 * @var AnnotatedInterface|null
46
	 */
47
	public $parent = null;
48
49
	/**
50
	 * Parent model field name
51
	 * @var string
52
	 */
53
	public $field = '';
54
55
	/**
56
	 * Get data from error. This will
57
	 * be called also when trying to recover.
58
	 * @return array
59
	 */
60
	public function getData()
61
	{
62
		return $this->modelData;
63
	}
64
65
	/**
66
	 * @param array $data
67
	 */
68
	public function setData($data)
69
	{
70
		$this->modelData = $data;
71
	}
72
73
74
}