AggregateEventPublisherImpl   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 92
ccs 35
cts 35
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A published() 0 7 1
A publishes() 0 11 1
B publish() 0 32 3
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\Test\Saga;
26
27
use Governor\Framework\Domain\EventMessageInterface;
28
use Governor\Framework\Domain\GenericDomainEventMessage;
29
30
/**
31
 *
32
 * @author    "David Kalosi" <[email protected]>
33
 * @license   <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a>
34
 */
35
class AggregateEventPublisherImpl implements GivenAggregateEventPublisherInterface, WhenAggregateEventPublisherInterface
36
{
37
    /**
38
     * @var string
39
     */
40
    private $aggregateIdentifier;
41
42
    /**
43
     * @var int
44
     */
45
    private $scn;
46
47
    private $fixture;
48
49 3
    function __construct(AnnotatedSagaTestFixture $fixture, $aggregateIdentifier)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
50
    {
51 3
        $this->aggregateIdentifier = $aggregateIdentifier;
52 3
        $this->scn = 0;
53 3
        $this->fixture = $fixture;
54 3
    }
55
56
57
    /**
58
     * Register the given <code>events</code> as being published somewhere in the past. These events are used to
59
     * prepare
60
     * the state of Sagas listening to them. Any commands or events sent out by the saga as reaction to these events is
61
     * ignored.
62
     *
63
     * @param array $events The events published by the aggregate
64
     * @return ContinuedGivenStateInterface a reference to the fixture to support a fluent interface
65
     */
66 2
    public function published(array $events)
67
    {
68 2
        $this->publish($events);
69
70 2
        return $this->fixture;
71
72
    }
73
74
    /**
75
     * Register the given <code>event</code> to be published on behalf of an aggregate. Activity caused by this event
76
     * on
77
     * the CommandBus and EventBus is monitored and can be checked in the FixtureExecutionResult.
78
     *
79
     * @param mixed $event The event published by the aggregate
80
     * @return FixtureExecutionResultInterface a reference to the test results for the validation  phase
81
     */
82 3
    public function publishes($event)
83
    {
84
        try {
85 3
            $this->publish(array($event));
86 3
        } finally {
87
            //FixtureResourceParameterResolverFactory.clear();
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
88
        }
89
90 3
        return $this->fixture->fixtureExecutionResult;
91
92
    }
93
94 3
    private function publish(array $events)
95
    {
96
        //DateTimeUtils.setCurrentMillisFixed(currentTime().getMillis());
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
97
98
        try {
99 3
            foreach ($events as $event) {
100 3
                if ($event instanceof EventMessageInterface) {
101
                    //eventMessage = (EventMessage) event;
102 1
                    $this->fixture->sagaManager->handle(
103 1
                        new GenericDomainEventMessage(
104 1
                            $this->aggregateIdentifier,
105 1
                            $this->scn++,
106 1
                            $event->getPayload(),
107 1
                            $event->getMetaData(),
108 1
                            $event->getIdentifier(),
109 1
                            $event->getTimestamp()
110 1
                        )
111 1
                    );
112 1
                } else {
113 2
                    $this->fixture->sagaManager->handle(
114 2
                        new GenericDomainEventMessage(
115 2
                            $this->aggregateIdentifier,
116 2
                            $this->scn++,
117
                            $event
118 2
                        )
119 2
                    );
120
                }
121 3
            }
122 3
        } finally {
123
            //DateTimeUtils.setCurrentMillisSystem();
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
124
        }
125
    }
126
}