Completed
Push — master ( ef46bd...45441d )
by Jeroen De
02:58
created

ParamType::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace ParamProcessor\PackagePrivate;
4
5
use ParamProcessor\ParamDefinition;
6
use ValueParsers\NullParser;
7
use ValueValidators\NullValidator;
8
9
class ParamType {
10
11
	private $typeId;
12
13
	private $className;
14
	private $stringParser;
15
	private $typedParser;
16
	private $validator;
17
	private $validationCallback;
18
19 14
	private function __construct( string $typeId ) {
20 14
		$this->typeId = $typeId;
21 14
	}
22
23 14
	public static function newFromArray( string $typeId, array $spec ): self {
24 14
		$type = new self( $typeId );
25
26 14
		$type->className = array_key_exists( 'definition', $spec ) ? $spec['definition'] : ParamDefinition::class;
27 14
		$type->stringParser = array_key_exists( 'string-parser', $spec ) ? $spec['string-parser'] : NullParser::class;
28 14
		$type->typedParser = array_key_exists( 'typed-parser', $spec ) ? $spec['typed-parser'] : NullParser::class;
29 14
		$type->validator = array_key_exists( 'validator', $spec ) ? $spec['validator'] : NullValidator::class;
30 14
		$type->validationCallback = array_key_exists( 'validation-callback', $spec ) ? $spec['validation-callback'] : null;
31
32 14
		return $type;
33
	}
34
35 50
	public function getClassName(): string {
36 50
		return $this->className;
37
	}
38
39 50
	public function getValidatorClass(): string {
40 50
		return $this->validator;
41
	}
42
43 50
	public function getValidationCallback(): ?callable {
44 50
		return $this->validationCallback;
45
	}
46
47 78
	public function getStringParserClass(): string {
48 78
		return $this->stringParser;
49
	}
50
51 50
	public function getTypedParserClass(): string {
52 50
		return $this->typedParser;
53
	}
54
55
}
56