GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AbstractEventSourcedAggregateRoot::apply()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 44 and the first side effect is on line 116.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*
3
 * Copyright (c) 2012-2014 Janos Szurovecz
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6
 * this software and associated documentation files (the "Software"), to deal in
7
 * the Software without restriction, including without limitation the rights to
8
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
 * of the Software, and to permit persons to whom the Software is furnished to do
10
 * so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included in all
13
 * copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
 * SOFTWARE.
22
 */
23
24
namespace predaddy\domain\eventsourcing;
25
26
use Iterator;
27
use predaddy\domain\AbstractAggregateRoot;
28
use predaddy\domain\DomainEvent;
29
use predaddy\eventhandling\EventBus;
30
use predaddy\eventhandling\EventFunctionDescriptorFactory;
31
use predaddy\messagehandling\MessageBus;
32
use predaddy\messagehandling\annotation\Subscribe;
33
34
/**
35
 * You can send an event which will be handled by all handler methods
36
 * inside the aggregate root, after that they will be sent to all outer event handlers.
37
 *
38
 * Handler methods must be annotated with "Subscribe"
39
 * and must be private or protected methods. You can override this behaviour
40
 * with setInnerMessageBusFactory() method.
41
 *
42
 * @author Janos Szurovecz <[email protected]>
43
 */
44
abstract class AbstractEventSourcedAggregateRoot extends AbstractAggregateRoot implements EventSourcedAggregateRoot
45
{
46
    /**
47
     * @var EventSourcingEventHandlerDescriptorFactory
48
     */
49
    private static $descriptorFactory;
50
51
    public static function init()
52
    {
53
        self::$descriptorFactory = new EventSourcingEventHandlerDescriptorFactory(
54
            new EventFunctionDescriptorFactory()
55
        );
56
    }
57
58
    /**
59
     * @param AbstractEventSourcedAggregateRoot $aggregateRoot
60
     * @return EventBus
61
     */
62
    private static function createInnerEventBus(AbstractEventSourcedAggregateRoot $aggregateRoot)
63
    {
64
        $bus = EventBus::builder()
65
            ->withIdentifier(static::className())
66
            ->withHandlerDescriptorFactory(self::$descriptorFactory)
67
            ->build();
68
        $bus->register($aggregateRoot);
69
        return $bus;
70
    }
71
72
    /**
73
     * Useful in case of Event Sourcing.
74
     *
75
     * @see EventSourcingRepository
76
     * @param Iterator $events DomainEvent iterator
77
     */
78
    final public function loadFromHistory(Iterator $events)
79
    {
80
        $bus = self::createInnerEventBus($this);
81
        foreach ($events as $event) {
82
            $this->handleEventInAggregate($event, $bus);
83
        }
84
    }
85
86
    /**
87
     * Fire a domain event from a handler method.
88
     *
89
     * @param DomainEvent $event
90
     */
91
    final protected function apply(DomainEvent $event)
92
    {
93
        $this->handleEventInAggregate($event);
94
        parent::raise($event);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (raise() instead of apply()). Are you sure this is correct? If so, you might want to change this to $this->raise().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
95
    }
96
97
    /**
98
     * Updates stateHash field when replaying events. Should not be called directly.
99
     *
100
     * @Subscribe
101
     * @param DomainEvent $event
102
     */
103
    final protected function updateStateHash(DomainEvent $event)
104
    {
105
        $this->setStateHash($event->stateHash());
106
    }
107
108
    private function handleEventInAggregate(DomainEvent $event, MessageBus $innerBus = null)
109
    {
110
        if ($innerBus === null) {
111
            $innerBus = self::createInnerEventBus($this);
112
        }
113
        $innerBus->post($event);
114
    }
115
}
116
AbstractEventSourcedAggregateRoot::init();
117