GenericDomainEventMessage   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 93
Duplicated Lines 12.9 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 96.77%

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 7
c 6
b 1
f 0
lcom 1
cbo 2
dl 12
loc 93
ccs 30
cts 31
cp 0.9677
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 12 12 1
A getAggregateIdentifier() 0 4 1
A getScn() 0 4 1
A andMetaData() 0 15 2
A withMetaData() 0 15 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * The software is based on the Axon Framework project which is
17
 * licensed under the Apache 2.0 license. For more information on the Axon Framework
18
 * see <http://www.axonframework.org/>.
19
 * 
20
 * This software consists of voluntary contributions made by many individuals
21
 * and is licensed under the MIT license. For more information, see
22
 * <http://www.governor-framework.org/>.
23
 */
24
25
namespace Governor\Framework\Domain;
26
27
/**
28
 * Description of GenericDomainEventMessage
29
 *
30
 * @author    "David Kalosi" <[email protected]>
31
 * @license   <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a>
32
 */
33
class GenericDomainEventMessage extends GenericEventMessage implements DomainEventMessageInterface
34
{
35
36
    /**
37
     * @var string
38
     */
39
    private $aggregateIdentifier;
40
    /**
41
     * @var int
42
     */
43
    private $scn;
44
45
    /**
46
     *
47
     * @param string $aggregateIdentifier
48
     * @param integer $scn
49
     * @param mixed $payload
50
     * @param MetaData $metadata
51
     * @param string $id
52
     * @param \DateTime $timestamp
53
     */
54 61 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
        $aggregateIdentifier,
56
        $scn,
57
        $payload,
58
        MetaData $metadata = null,
59
        $id = null,
60
        \DateTime $timestamp = null
61
    ) {
62 61
        parent::__construct($payload, $metadata, $id, $timestamp);
63 61
        $this->aggregateIdentifier = $aggregateIdentifier;
64 61
        $this->scn = $scn;
65 61
    }
66
67
    /**
68
     * @return string
69
     */
70 43
    public function getAggregateIdentifier()
71
    {
72 43
        return $this->aggregateIdentifier;
73
    }
74
75
    /**
76
     * @return int
77
     */
78 47
    public function getScn()
79
    {
80 47
        return $this->scn;
81
    }
82
83
    /**
84
     *
85
     * @param array $metadata
86
     * @return GenericDomainEventMessage
87
     */
88 4
    public function andMetaData(array $metadata = [])
89
    {
90 4
        if (empty($metadata)) {
91 1
            return $this;
92
        }
93
94 4
        return new GenericDomainEventMessage(
95 4
            $this->getAggregateIdentifier(),
96 4
            $this->scn,
97 4
            $this->getPayload(),
98 4
            $this->getMetaData()->mergeWith($metadata),
99 4
            $this->getIdentifier(),
100 4
            $this->getTimestamp()
101 4
        );
102
    }
103
104
    /**
105
     *
106
     * @param array $metadata
107
     * @return GenericDomainEventMessage
108
     */
109 3
    public function withMetaData(array $metadata = [])
110
    {
111 3
        if ($this->getMetaData()->isEqualTo($metadata)) {
112
            return $this;
113
        }
114
115 3
        return new GenericDomainEventMessage(
116 3
            $this->aggregateIdentifier,
117 3
            $this->scn,
118 3
            $this->getPayload(),
119 3
            new MetaData($metadata),
120 3
            $this->getIdentifier(),
121 3
            $this->getTimestamp()
122 3
        );
123
    }
124
125
}
126