Completed
Branch ddd-changes (96d3bc)
by Gabriel
05:08
created

AbstractDomainEvent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 51
ccs 14
cts 14
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getOccurredOn() 0 4 1
A getPayload() 0 5 1
A getEventVersion() 0 4 1
getAdditionalPayload() 0 1 ?
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Baleen\Migrations\Shared\Event;
21
22
use DateTime;
23
24
/**
25
 * Class AbstractDomainEvent
26
 *
27
 * @author Gabriel Somoza <[email protected]>
28
 */
29
abstract class AbstractDomainEvent implements DomainEventInterface
30
{
31
    /** @var DateTime */
32
    private $occurredOn;
33
34
    /**
35
     * AbstractDomainEvent constructor.
36
     *
37
     * @param DateTime $createdOn
0 ignored issues
show
Documentation introduced by
Should the type for parameter $createdOn not be null|DateTime?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
38
     */
39 33
    public function __construct(DateTime $createdOn = null)
40
    {
41 33
        if (null === $createdOn) {
42 28
            $createdOn = new DateTime(); // now
43 28
        }
44
45 33
        $this->occurredOn = $createdOn;
46 33
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51 5
    final public function getOccurredOn()
52
    {
53 5
        return $this->occurredOn;
54
    }
55
56
    /**
57
     * @inheritdoc
58
     */
59 3
    final public function getPayload() {
60 3
        return array_merge([
61 3
            'occurred_on' => $this->getOccurredOn(),
62 3
        ], $this->getAdditionalPayload());
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68 1
    public function getEventVersion()
69
    {
70 1
        return 1;
71
    }
72
73
    /**
74
     * Custom getPayload fields, to be merged with default getPayload.
75
     *
76
     * @return array
77
     */
78
    abstract protected function getAdditionalPayload();
79
}
80