HybridDoctrineRepository   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 32.14 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 3
dl 18
loc 56
ccs 0
cts 29
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A doDeleteWithLock() 9 9 2
A doSaveWithLock() 9 9 2
A getTypeIdentifier() 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\EventSourcing;
26
27
use Governor\Framework\Repository\GenericOrmRepository;
28
use Governor\Framework\EventHandling\EventBusInterface;
29
use Governor\Framework\Repository\LockManagerInterface;
30
use Governor\Framework\EventStore\EventStoreInterface;
31
use Governor\Framework\Domain\AggregateRootInterface;
32
use Doctrine\ORM\EntityManager;
33
34
/**
35
 * Description of HybridDoctrineRepository
36
 *
37
 * @author    "David Kalosi" <[email protected]>  
38
 * @license   <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> 
39
 */
40
class HybridDoctrineRepository extends GenericOrmRepository
41
{
42
43
    /**
44
     * @var EventStoreInterface 
45
     */
46
    private $eventStore;
47
    
48
    /**     
49
     * @var string
50
     */
51
    private $aggregateTypeIdentifier;
52
53
    public function __construct($className, EventBusInterface $eventBus,
54
        LockManagerInterface $lockManager, EntityManager $entityManager,
55
        EventStoreInterface $eventStore)
56
    {
57
        parent::__construct($className, $eventBus, $lockManager, $entityManager);
58
        $this->eventStore = $eventStore;
59
        
60
        $reflClass = new \ReflectionClass($className);
61
        $this->aggregateTypeIdentifier = $reflClass->getShortName();
62
    }
63
64 View Code Duplication
    protected function doDeleteWithLock(AggregateRootInterface $aggregate)
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...
65
    {
66
        if (null !== $this->eventStore) {
67
            $this->eventStore->appendEvents($this->getTypeIdentifier(),
68
                $aggregate->getUncommittedEvents());
69
        }
70
71
        parent::doDeleteWithLock($aggregate);
72
    }
73
74 View Code Duplication
    protected function doSaveWithLock(AggregateRootInterface $aggregate)
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...
75
    {
76
        if (null !== $this->eventStore) {
77
            $this->eventStore->appendEvents($this->getTypeIdentifier(),
78
                $aggregate->getUncommittedEvents());
79
        }
80
81
        parent::doSaveWithLock($aggregate);
82
    }
83
84
    /**
85
     * Returns the type identifier to use when appending events in the event store. Default to the simple class name of
86
     * the aggregateType provided in the constructor.
87
     *
88
     * @return string the type identifier to use when appending events in the event store.
89
     */
90
    protected function getTypeIdentifier()
91
    {
92
        return $this->aggregateTypeIdentifier;
93
    }
94
95
}
96