SagaEntry   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 114
Duplicated Lines 23.68 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 96.43%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 7
c 4
b 0
f 0
lcom 1
cbo 6
dl 27
loc 114
ccs 27
cts 28
cp 0.9643
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 1
A getSaga() 16 16 2
A getSerializedSaga() 0 4 1
A getSagaId() 0 4 1
A getRevision() 0 4 1
A getSagaType() 0 4 1

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\Saga\Repository\Orm;
26
27
use Doctrine\ORM\Mapping as ORM;
28
use Governor\Framework\Saga\SagaInterface;
29
use Governor\Framework\Serializer\SerializerInterface;
30
use Governor\Framework\Serializer\SimpleSerializedObject;
31
use Governor\Framework\Serializer\SimpleSerializedType;
32
33
/**
34
 * Class defining a Saga in the ORM.
35
 *
36
 * @author    "David Kalosi" <[email protected]>
37
 * @license   <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a>
38
 * @ORM\Entity
39
 * @ORM\Table(name="governor_sagas")
40
 */
41
class SagaEntry
42
{
43
44
    /**
45
     * @ORM\Id
46
     * @ORM\Column(type="string", name="saga_id")
47
     * @var string
48
     */
49
    private $sagaId;
50
51
    /**
52
     * @ORM\Column(type="string", name="saga_type")
53
     * @var string
54
     */
55
    private $sagaType;
56
    /**
57
     * @ORM\Column(type="string", name="saga_revision", nullable=true)
58
     * @var string
59
     */
60
    private $revision;
61
    /**
62
     * @ORM\Column(type="text", name="serialized_saga")
63
     * @var string
64
     */
65
    private $serializedSaga;
66
67
    /**
68
     * @var SagaInterface
69
     */
70
    private $saga;
71
72
    /**
73
     * Constructs a new SagaEntry for the given <code>saga</code>. The given saga must be serializable. The provided
74
     * saga is not modified by this operation.
75
     *
76
     * @param SagaInterface $saga The saga to store
77
     * @param SerializerInterface $serializer The serialization mechanism to convert the Saga to a byte stream
78
     */
79 9 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...
80
        SagaInterface $saga,
81
        SerializerInterface $serializer
82
    ) {
83 9
        $this->sagaId = $saga->getSagaIdentifier();
84 9
        $serialized = $serializer->serialize($saga);
85 9
        $this->serializedSaga = $serialized->getData();
86 9
        $this->sagaType = $serialized->getType()->getName();
87 9
        $this->revision = $serialized->getType()->getRevision();
88 9
        $this->saga = $saga;
89 9
    }
90
91
    /**
92
     * Returns the Saga instance stored in this entry.
93
     *
94
     * @param SerializerInterface $serializer The serializer to decode the Saga
95
     * @return SagaInterface the Saga instance stored in this entry
96
     */
97 1 View Code Duplication
    public function getSaga(SerializerInterface $serializer)
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...
98
    {
99 1
        if (null !== $this->saga) {
100
            return $this->saga;
101
        }
102
103 1
        return $serializer->deserialize(
104 1
            new SimpleSerializedObject(
105 1
                $this->serializedSaga,
106 1
                new SimpleSerializedType(
107 1
                    $this->sagaType,
108 1
                    $this->revision
109 1
                )
110 1
            )
111 1
        );
112
    }
113
114
    /**
115
     * Returns the serialized form of the Saga.
116
     *
117
     * @return string the serialized form of the Saga
118
     */
119 9
    public function getSerializedSaga()
120
    {
121 9
        return $this->serializedSaga;
122
    }
123
124
    /**
125
     * Returns the identifier of the saga contained in this entry
126
     *
127
     * @return string the identifier of the saga contained in this entry
128
     */
129 3
    public function getSagaId()
130
    {
131 3
        return $this->sagaId;
132
    }
133
134
    /**
135
     * Returns the revision of the serialized saga
136
     *
137
     * @return string the revision of the serialized saga
138
     */
139 6
    public function getRevision()
140
    {
141 6
        return $this->revision;
142
    }
143
144
    /**
145
     * Returns the type identifier of the serialized saga.
146
     *
147
     * @return string the type identifier of the serialized saga
148
     */
149 6
    public function getSagaType()
150
    {
151 6
        return $this->sagaType;
152
    }
153
154
}
155