SimpleCommandHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 5
c 1
b 0
f 0
dl 0
loc 22
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A saveToRepository() 0 3 1
A __construct() 0 3 1
A loadFromRepository() 0 3 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