Completed
Push — master ( bb43db...b49a56 )
by Iqbal
02:27
created

AbstractReadModel::mapBaseOnKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
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()) {
0 ignored issues
show
Unused Code introduced by
$mappings is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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()) {
0 ignored issues
show
Unused Code introduced by
$mappings is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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