Completed
Push — master ( 84505b...5678fc )
by Ivannis Suárez
02:56
created

PublishedPostProjector::readModelsFromRepository()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 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\Projector;
13
14
use Cubiche\Core\Cqrs\WriteModelInterface;
15
use Cubiche\Domain\EventSourcing\Projector\Action;
16
use Cubiche\Domain\EventSourcing\Projector\Projection;
17
use Cubiche\Domain\EventSourcing\Projector\Projector;
18
use Cubiche\Domain\EventSourcing\Tests\Fixtures\Event\PostTitleWasChanged;
19
use Cubiche\Domain\EventSourcing\Tests\Fixtures\Event\PostWasPublished;
20
use Cubiche\Domain\EventSourcing\Tests\Fixtures\Event\PostWasUnPublished;
21
use Cubiche\Domain\EventSourcing\Tests\Fixtures\PostEventSourced;
22
use Cubiche\Domain\EventSourcing\Tests\Fixtures\ReadModel\PublishedPost;
23
use Cubiche\Domain\Model\IdInterface;
24
25
/**
26
 * PublishedPostProjector class.
27
 *
28
 * @author Ivannis Suárez Jerez <[email protected]>
29
 */
30
class PublishedPostProjector extends Projector
31
{
32
    /**
33
     * @param Projection          $projection
34
     * @param PostTitleWasChanged $event
35
     */
36
    public function projectPostTitleWasChanged(Projection $projection, PostTitleWasChanged $event)
37
    {
38
        /** @var PublishedPost $readModel */
39
        $readModel = $projection->readModel();
40
41
        $readModel->setTitle($event->title());
42
    }
43
44
    /**
45
     * @param Projection       $projection
46
     * @param PostWasPublished $event
47
     */
48
    public function projectPostWasPublished(Projection $projection, 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...
49
    {
50
        $projection->setAction(Action::CREATE());
51
    }
52
53
    /**
54
     * @param Projection         $projection
55
     * @param PostWasUnPublished $event
56
     */
57
    public function projectPostWasUnPublished(Projection $projection, 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...
58
    {
59
        $projection->setAction(Action::REMOVE());
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    protected function readModelsFromRepository(IdInterface $writeModelId)
66
    {
67
        $readModel = $this->repository->get($writeModelId);
68
        if ($readModel !== null) {
69
            return array($readModel);
70
        }
71
72
        return array();
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    protected function readModelsFromWriteModel(WriteModelInterface $writeModel)
79
    {
80
        /** @var PostEventSourced $aggregate */
81
        $aggregate = $writeModel;
82
83
        return array(
84
            new PublishedPost(
85
                $aggregate->id(),
0 ignored issues
show
Compatibility introduced by
$aggregate->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...
86
                $aggregate->title()
87
            ),
88
        );
89
    }
90
91
    /**
92
     * @return string
93
     */
94
    protected function writeModelClass()
95
    {
96
        return PostEventSourced::class;
97
    }
98
}
99