Completed
Push — master ( 56bc9c...60540e )
by Peter
08:17
created

SelectDecorator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 23
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A decorate() 0 20 4
1
<?php
2
3
4
namespace Maslosoft\Manganel\Decorators\QueryBuilder;
5
6
7
use function array_keys;
8
use Maslosoft\Manganel\Interfaces\QueryBuilder\BodyDecoratorInterface;
9
use Maslosoft\Manganel\SearchCriteria;
10
use function in_array;
11
12
class SelectDecorator implements BodyDecoratorInterface
13
{
14 32
	public function decorate(&$conditions, SearchCriteria $criteria)
15
	{
16 32
		$fields = array_keys($criteria->getSelect());
17 32
		if (empty($fields))
18
		{
19 29
			return;
20
		}
21
		// Ensure _class field as it is required by SearchFinder
22 3
		if(!in_array('_class', $fields, true))
23
		{
24 3
			$fields[] = '_class';
25
		}
26 3
		$c = $criteria->getConditions();
27
		// Empty conditions results in match_all, which fails when there is a _source too
28
		// Exception request does not support [_source]
29 3
		if(!empty($c))
30
		{
31 1
			$conditions['_source'] = $fields;
32
		}
33
	}
34
}