|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Borobudur-Cqrs package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Hexacodelabs <http://hexacodelabs.com> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Borobudur\Cqrs\ReadModel; |
|
12
|
|
|
|
|
13
|
|
|
use Borobudur\Bus\Message\MessageMapperTrait; |
|
14
|
|
|
use Borobudur\Parameterize\Mapper\ParameterMapper; |
|
15
|
|
|
use Borobudur\Parameterize\ParameterBag; |
|
16
|
|
|
use Borobudur\Serialization\Serializer\Mixin\DeserializerTrait; |
|
17
|
|
|
use Borobudur\Serialization\Serializer\Mixin\SerializerTrait; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Iqbal Maulana <[email protected]> |
|
21
|
|
|
* @created 8/18/15 |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract class AbstractReadModel implements ReadModelInterface |
|
24
|
|
|
{ |
|
25
|
|
|
use SerializerTrait, DeserializerTrait, MessageMapperTrait { |
|
26
|
|
|
SerializerTrait::serialize as serializeData; |
|
27
|
|
|
DeserializerTrait::deserialize as deserializeData; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @return array |
|
32
|
|
|
*/ |
|
33
|
|
|
public static function mappings() |
|
34
|
|
|
{ |
|
35
|
|
|
return array(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
|
|
public static function deserialize(array $attributes) |
|
42
|
|
|
{ |
|
43
|
|
|
if ($mappings = static::mappings()) { |
|
|
|
|
|
|
44
|
|
|
$attributes = static::mapBaseOnKeys($attributes, array_flip(static::mappings())); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return static::deserializeData($attributes); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritdoc} |
|
52
|
|
|
*/ |
|
53
|
|
|
public function serialize() |
|
54
|
|
|
{ |
|
55
|
|
|
$serialized = $this->serializeData(); |
|
56
|
|
|
|
|
57
|
|
|
if ($mappings = static::mappings()) { |
|
|
|
|
|
|
58
|
|
|
$serialized = static::mapBaseOnKeys($serialized, static::mappings()); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $serialized; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Mapping data base on mapping keys. |
|
66
|
|
|
* |
|
67
|
|
|
* @param array $attributes |
|
68
|
|
|
* @param array $mappingKeys |
|
69
|
|
|
* |
|
70
|
|
|
* @return array |
|
71
|
|
|
*/ |
|
72
|
|
|
protected static function mapBaseOnKeys(array $attributes, array $mappingKeys) |
|
73
|
|
|
{ |
|
74
|
|
|
return (array) ParameterMapper::map(new ParameterBag($attributes), $mappingKeys); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.