SelectDecorator::decorate()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 10
cts 10
cp 1
rs 9.6
c 0
b 0
f 0
cc 4
nc 5
nop 2
crap 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
}