AbstractDomainEvent   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getOccurredOn() 0 4 1
A getVersion() 0 4 1
A getPayload() 0 6 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\Common\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
    /** @var int */
35
    private $version;
36
37
    /**
38
     * AbstractDomainEvent constructor.
39
     *
40
     * @param DateTime $occurredOn
0 ignored issues
show
Documentation introduced by
Should the type for parameter $occurredOn 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...
41
     * @param int $sequenceId
0 ignored issues
show
Documentation introduced by
Should the type for parameter $sequenceId not be integer|null?

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...
42
     */
43 34
    public function __construct(DateTime $occurredOn = null, $sequenceId = null)
44
    {
45 34
        if (null === $occurredOn) {
46 29
            $occurredOn = new DateTime(); // now
47 29
        }
48 34
        $this->occurredOn = $occurredOn;
49 34
        $this->version = (int) $sequenceId;
50 34
    }
51
52
    /**
53
     * @inheritdoc
54
     */
55 5
    final public function getOccurredOn()
56
    {
57 5
        return $this->occurredOn;
58
    }
59
60
    /**
61
     * @return int
62
     */
63 4
    public function getVersion()
64
    {
65 4
        return $this->version;
66
    }
67
68
    /**
69
     * @inheritdoc
70
     */
71 3
    final public function getPayload() {
72 3
        return array_merge([
73 3
            'occurred_on' => $this->getOccurredOn(),
74 3
            'sequence_id' => $this->getVersion(),
75 3
        ], $this->getAdditionalPayload());
76
    }
77
78
    /**
79
     * Custom getPayload fields, to be merged with default getPayload.
80
     *
81
     * @return array
82
     */
83
    abstract protected function getAdditionalPayload();
84
}
85