Completed
Push — master ( 73d790...a6f521 )
by Ron
02:28
created

RequiredDBFilterMap::from()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 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
	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
	 * @param string $expression
25
	 * @param string|string[] $keyPath
26
	 * @param callable|null $validator
27
	 * @return DBExprFilter
28
	 */
29
	public function __invoke($expression, $keyPath, $validator = null) {
30
		return new DBExprFilter($expression, $this->map, $keyPath, $validator, function ($result, array $data) {
31
			if(!$result) {
32
				throw new RequiredValueNotFoundException(sprintf("Required value %s not found", $data['key']));
33
			}
34
		});
35
	}
36
}
37