Completed
Push — master ( 039b1a...93e4df )
by Jeroen De
01:39
created

ParamType::getStringParserClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
	private function __construct( string $typeId ) {
20
		$this->typeId = $typeId;
21
	}
22
23
	public static function newFromArray( string $typeId, array $spec ): self {
24
		$type = new self( $typeId );
25
26
		$type->className = array_key_exists( 'definition', $spec ) ? $spec['definition'] : ParamDefinition::class;
27
		$type->stringParser = array_key_exists( 'string-parser', $spec ) ? $spec['string-parser'] : NullParser::class;
28
		$type->typedParser = array_key_exists( 'typed-parser', $spec ) ? $spec['typed-parser'] : NullParser::class;
29
		$type->validator = array_key_exists( 'validator', $spec ) ? $spec['validator'] : NullValidator::class;
30
		$type->validationCallback = array_key_exists( 'validation-callback', $spec ) ? $spec['validation-callback'] : null;
31
32
		return $type;
33
	}
34
35 36
	public function getClassName(): string {
36 36
		return $this->className;
37
	}
38
39 36
	public function getValidatorClass(): string {
40 36
		return $this->validator;
41
	}
42
43 36
	public function getValidationCallback(): ?callable {
44 36
		return $this->validationCallback;
45
	}
46
47 64
	public function getStringParserClass(): string {
48 64
		return $this->stringParser;
49
	}
50
51 50
	public function getTypedParserClass(): string {
52 50
		return $this->typedParser;
53
	}
54
55
}
56