Completed
Push — master ( 63d3cc...fb2a6e )
by Peter
06:57
created

OrDecorator::useWith()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL, Commercial` license[s].
5
 *
6
 * @package maslosoft/manganel
7
 * @license AGPL, Commercial
8
 *
9
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
10
 * @link https://maslosoft.com/manganel/
11
 */
12
13
namespace Maslosoft\Manganel\Decorators\QueryBuilder\Operators;
14
15
use function array_merge;
16
use function codecept_debug;
17
use Maslosoft\Manganel\Helpers\ArrayFiller;
18
use Maslosoft\Manganel\Interfaces\QueryBuilder\OperatorDecoratorInterface;
19
20
/**
21
 * OrDecorator
22
 *
23
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
24
 */
25
class OrDecorator implements OperatorDecoratorInterface
26
{
27
28 31
	public function useWith($key, $value)
29
	{
30 31
		return $key == '$or';
31
	}
32
33 5
	public function decorate(&$condition, $name, $value)
34
	{
35 5
		$should = [];
36 5
		foreach($value as $termsSet)
37
		{
38 5
			foreach ($termsSet as $term => $values)
39
			{
40 5
				foreach ($values as $value)
41
				{
42 5
					$should[] = [
43
						'term' => [
44 5
							$term => $value
45
						]
46
					];
47
				}
48
			}
49
		}
50 5
		$condition = ArrayFiller::fill($condition, 'bool.should', []);
51
52 5
		$condition['bool']['should'] = array_merge($condition['bool']['should'], $should);
53 5
	}
54
55
}
56