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

RequiredDBFilterMap   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 33
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A from() 0 3 1
A __invoke() 0 7 2
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