OrDecorator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 16.66%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 31
ccs 2
cts 12
cp 0.1666
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A useWith() 0 4 1
A decorate() 0 21 4
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL-3.0-only, proprietary` license[s].
5
 *
6
 * @package maslosoft/manganel
7
 * @license AGPL-3.0-only, proprietary
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 3
	public function useWith($key, $value)
29
	{
30 3
		return $key == '$or';
31
	}
32
33
	public function decorate(&$condition, $name, $value)
34
	{
35
		$should = [];
36
		foreach($value as $termsSet)
37
		{
38
			foreach ($termsSet as $term => $values)
39
			{
40
				foreach ($values as $value)
41
				{
42
					$should[] = [
43
						'term' => [
44
							$term => $value
45
						]
46
					];
47
				}
48
			}
49
		}
50
		$condition = ArrayFiller::fill($condition, 'bool.should', []);
51
52
		$condition['bool']['should'] = array_merge($condition['bool']['should'], $should);
53
	}
54
55
}
56