ResultFormatRegistrator::withName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace ModernTimeline\ResultFacade;
6
7
class ResultFormatRegistrator {
8
9
	/**
10
	 * @var callable
11
	 */
12
	private $registry;
13
14
	private string $name;
15
	private string $nameMessageKey;
16 5
	private array $parameterDefinitions;
17 5
18 5
	/**
19
	 * @var callable
20 5
	 */
21 5
	private $constructionFunction;
22 5
23
	public function __construct( callable $registry ) {
24
		$this->registry = $registry;
25 5
	}
26 5
27 5
	public function withName( string $name ): self {
28
		$this->name = $name;
29
		return $this;
30 5
	}
31 5
32 5
	public function andMessageKey( string $nameMessageKey ): self {
33
		$this->nameMessageKey = $nameMessageKey;
34
		return $this;
35 5
	}
36 5
37 5
	public function andParameterDefinitions( array $parameterDefinitions ): self {
38
		$this->parameterDefinitions = $parameterDefinitions;
39
		return $this;
40 5
	}
41 5
42 5
	public function andPresenterBuilder( callable $constructionFunction ): self {
43
		$this->constructionFunction = $constructionFunction;
44 5
		return $this;
45 5
	}
46 5
47 5
	public function register(): void {
48 5
		call_user_func( $this->registry, $this->newResultFormat() );
49 5
	}
50
51
	private function newResultFormat(): ResultFormat {
52
		return new ResultFormat(
53
			$this->name,
54
			$this->nameMessageKey,
55
			$this->parameterDefinitions,
56
			$this->constructionFunction
57
		);
58
	}
59
60
}
61