AggregateRootStub::id()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\SharedKernel\Tests\Double\Domain\Model;
16
17
use Kreta\SharedKernel\Domain\Model\AggregateRoot;
18
use Kreta\SharedKernel\Domain\Model\EventSourcedAggregateRoot;
19
use Kreta\SharedKernel\Domain\Model\Identity\Id;
20
use Kreta\SharedKernel\Event\Stream;
21
22
class AggregateRootStub extends AggregateRoot implements EventSourcedAggregateRoot
23
{
24
    private $id;
25
    private $property;
26
27
    public function __construct(Id $id)
28
    {
29
        $this->id = $id;
30
    }
31
32
    public function id() : Id
33
    {
34
        return $this->id;
35
    }
36
37
    public function property() : string
38
    {
39
        return $this->property;
40
    }
41
42
    public function foo()
43
    {
44
        $this->publish(new EventSourcingEventStub());
45
    }
46
47
    public function bar()
48
    {
49
        $this->property = 'bar';
50
        $this->publish(new CqrsEventStub());
51
    }
52
53
    protected function applyEventSourcingEventStub()
54
    {
55
        $this->property = 'foo';
56
    }
57
58
    public static function reconstitute(Stream $stream) : self
59
    {
60
        $instance = new self($stream->name()->aggregateId());
61
62
        foreach ($stream as $event) {
0 ignored issues
show
Bug introduced by
The expression $stream of type object<Kreta\SharedKernel\Event\Stream> is not traversable.
Loading history...
63
            $instance->apply($event);
64
        }
65
66
        return $instance;
67
    }
68
}
69