AggregateRootStub   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 5
dl 0
loc 47
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A id() 0 4 1
A property() 0 4 1
A foo() 0 4 1
A bar() 0 5 1
A applyEventSourcingEventStub() 0 4 1
A reconstitute() 0 10 2
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