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

ParamType   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 0
dl 0
loc 47
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getClassName() 0 3 1
A getValidatorClass() 0 3 1
A getValidationCallback() 0 3 1
A getStringParserClass() 0 3 1
A getTypedParserClass() 0 3 1
A __construct() 0 3 1
A newFromArray() 0 11 6
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