Completed
Push — master ( 3097a5...bdf786 )
by Ron
03:10
created

RequiredDBFilterMap   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 36
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A from() 0 2 1
A __invoke() 0 4 2
A getMap() 0 2 1
1
<?php
2
namespace Kir\MySQL\Builder\Expr;
3
4
class RequiredDBFilterMap {
5
	/** @var array */
6
	private $map;
7
8
	/**
9
	 * @param array $map
10
	 */
11
	final public function __construct(array $map) {
12
		$this->map = $map;
13
	}
14
15
	/**
16
	 * @param array $map
17
	 * @return static
18
	 */
19
	public static function from(array $map) {
20
		return new static($map);
21
	}
22
23
	/**
24
	 * @return array
25
	 */
26
	protected function getMap(): array {
27
		return $this->map;
28
	}
29
30
	/**
31
	 * @param string $expression
32
	 * @param string|string[] $keyPath
33
	 * @param callable|null $validator
34
	 * @return DBExprFilter
35
	 */
36
	public function __invoke($expression, $keyPath, $validator = null) {
37
		return new DBExprFilter($expression, $this->map, $keyPath, $validator, static function ($result, array $data) {
38
			if(!$result) {
39
				throw new RequiredValueNotFoundException(sprintf("Required value %s not found", $data['key']));
40
			}
41
		});
42
	}
43
}
44