SimpleCommandHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
namespace Kepawni\Twilted\Basic;
3
4
use Kepawni\Twilted\EntityIdentifier;
5
use Kepawni\Twilted\EventSourcedEntity;
6
use Kepawni\Twilted\IdentifiableEventSourcedEntity;
7
use Kepawni\Twilted\Repository;
8
9
/**
10
 * A simple command handler that can load from and save to a repository.
11
 * Subclasses should provide a method for each command handled.
12
 */
13
abstract class SimpleCommandHandler
14
{
15
    private $repository;
16
17
    public function __construct(Repository $repository)
18
    {
19
        $this->repository = $repository;
20
    }
21
22
    /**
23
     * @param EntityIdentifier $aggregateId
24
     *
25
     * @return IdentifiableEventSourcedEntity
26
     */
27
    protected function loadFromRepository(EntityIdentifier $aggregateId): EventSourcedEntity
28
    {
29
        return $this->repository->load($aggregateId);
30
    }
31
32
    protected function saveToRepository(IdentifiableEventSourcedEntity $aggregate): void
33
    {
34
        $this->repository->save($aggregate);
35
    }
36
}
37