BasicMutationResponseBuilder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 42
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A create() 0 4 1
A build() 0 7 1
A addDomainEvent() 0 11 2
A addError() 0 4 1
1
<?php declare(strict_types = 1);
2
3
namespace TomCizek\ResponseRecorder\Application\ResponseRecorder\MutationResponse;
4
5
use Prooph\Common\Messaging\DomainEvent;
6
use TomCizek\ResponseRecorder\Application\ResponseRecorder\BasicMutationResponse;
7
use TomCizek\ResponseRecorder\Application\ResponseRecorder\MutationResponse\ErrorCollection\GenericShowableMutationError;
8
use TomCizek\ResponseRecorder\Application\ResponseRecorder\MutationResponse\ErrorCollection\ShowableMutationError;
9
use TomCizek\ResponseRecorder\DomainModel\TranslatableDomainErrorEvent;
10
11
class BasicMutationResponseBuilder
12
{
13
	/** @var DomainEvent[] */
14
	private $domainEvents = [];
15
16
	/** @var ShowableMutationError[] */
17
	private $errors = [];
18
19 9
	private function __construct()
20
	{
21 9
	}
22
23 9
	public static function create(): self
24
	{
25 9
		return new self();
26
	}
27
28 9
	public function build(): BasicMutationResponse
29
	{
30 9
		return BasicMutationResponse::create(
31 9
			new DomainEventCollection($this->domainEvents),
32 9
			new MutationErrorCollection($this->errors)
33
		);
34
	}
35
36 3
	public function addDomainEvent(DomainEvent $domainEvent): void
37
	{
38 3
		$this->domainEvents[] = $domainEvent;
39
40 3
		if ($domainEvent instanceof TranslatableDomainErrorEvent) {
41 2
			$this->errors[] = GenericShowableMutationError::create(
42 2
				$domainEvent->getErrorMessage(),
43 2
				$domainEvent->getErrorMessageParams()
44
			);
45
		}
46 3
	}
47
48 5
	public function addError(ShowableMutationError $showableMutationError): void
49
	{
50 5
		$this->errors[] = $showableMutationError;
51 5
	}
52
}
53