PostEventSourced   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 7

Importance

Changes 0
Metric Value
wmc 9
lcom 3
cbo 7
dl 0
loc 93
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A changeTitle() 0 6 1
A publish() 0 6 1
A unpublish() 0 6 1
A remove() 0 6 1
A applyPostWasCreated() 0 5 1
A applyPostTitleWasChanged() 0 4 1
A applyPostWasPublished() 0 4 1
A applyPostWasUnPublished() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Cubiche\Domain\EventSourcing\Tests\Fixtures;
13
14
use Cubiche\Domain\EventSourcing\EventSourcedAggregateRoot;
15
use Cubiche\Domain\EventSourcing\EventSourcedAggregateRootInterface;
16
use Cubiche\Domain\EventSourcing\Metadata\Annotations as ES;
17
use Cubiche\Domain\EventSourcing\Tests\Fixtures\Event\PostTitleWasChanged;
18
use Cubiche\Domain\EventSourcing\Tests\Fixtures\Event\PostWasCreated;
19
use Cubiche\Domain\EventSourcing\Tests\Fixtures\Event\PostWasPublished;
20
use Cubiche\Domain\EventSourcing\Tests\Fixtures\Event\PostWasRemoved;
21
use Cubiche\Domain\EventSourcing\Tests\Fixtures\Event\PostWasUnPublished;
22
use Cubiche\Domain\Model\Tests\Fixtures\Post;
23
use Cubiche\Domain\Model\Tests\Fixtures\PostId;
24
25
/**
26
 * PostEventSourced class.
27
 *
28
 * @author Ivannis Suárez Jerez <[email protected]>
29
 * @ES\Migratable
30
 */
31
class PostEventSourced extends Post implements EventSourcedAggregateRootInterface
32
{
33
    use EventSourcedAggregateRoot;
34
35
    /**
36
     * Post constructor.
37
     *
38
     * @param PostId $id
39
     * @param string $title
40
     * @param string $content
41
     */
42
    public function __construct(PostId $id, $title, $content)
43
    {
44
        $this->id = $id;
45
46
        $this->recordApplyAndPublishEvent(
47
            new PostWasCreated($this->id(), $title, $content)
0 ignored issues
show
Compatibility introduced by
$this->id() of type object<Cubiche\Domain\Model\IdInterface> is not a sub-type of object<Cubiche\Domain\Mo...\Tests\Fixtures\PostId>. It seems like you assume a concrete implementation of the interface Cubiche\Domain\Model\IdInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
48
        );
49
    }
50
51
    /**
52
     * @param $newTitle
53
     */
54
    public function changeTitle($newTitle)
55
    {
56
        $this->recordApplyAndPublishEvent(
57
            new PostTitleWasChanged($this->id, $newTitle)
0 ignored issues
show
Compatibility introduced by
$this->id of type object<Cubiche\Domain\Model\IdInterface> is not a sub-type of object<Cubiche\Domain\Mo...\Tests\Fixtures\PostId>. It seems like you assume a concrete implementation of the interface Cubiche\Domain\Model\IdInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
58
        );
59
    }
60
61
    /**
62
     * Publish a post.
63
     */
64
    public function publish()
65
    {
66
        $this->recordApplyAndPublishEvent(
67
            new PostWasPublished($this->id())
68
        );
69
    }
70
71
    /**
72
     * Unpublish a post.
73
     */
74
    public function unpublish()
75
    {
76
        $this->recordApplyAndPublishEvent(
77
            new PostWasUnPublished($this->id())
78
        );
79
    }
80
81
    /**
82
     * Publish a post.
83
     */
84
    public function remove()
85
    {
86
        $this->recordApplyAndPublishEvent(
87
            new PostWasRemoved($this->id())
0 ignored issues
show
Compatibility introduced by
$this->id() of type object<Cubiche\Domain\Model\IdInterface> is not a sub-type of object<Cubiche\Domain\Mo...\Tests\Fixtures\PostId>. It seems like you assume a concrete implementation of the interface Cubiche\Domain\Model\IdInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
88
        );
89
    }
90
91
    /**
92
     * @param PostWasCreated $event
93
     */
94
    protected function applyPostWasCreated(PostWasCreated $event)
95
    {
96
        $this->title = $event->title();
97
        $this->content = $event->content();
98
    }
99
100
    /**
101
     * @param PostTitleWasChanged $event
102
     */
103
    protected function applyPostTitleWasChanged(PostTitleWasChanged $event)
104
    {
105
        $this->title = $event->title();
106
    }
107
108
    /**
109
     * @param PostWasPublished $event
110
     */
111
    protected function applyPostWasPublished(PostWasPublished $event)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
112
    {
113
        $this->published = true;
114
    }
115
116
    /**
117
     * @param PostWasUnPublished $event
118
     */
119
    protected function applyPostWasUnPublished(PostWasUnPublished $event)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
120
    {
121
        $this->published = false;
122
    }
123
}
124