Completed
Push — master ( 6a8f4b...4a9289 )
by Peter
09:25
created

QueryBuilderDecorator::decorate()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 26
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 13
cts 13
cp 1
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 12
nc 6
nop 2
crap 4
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Maslosoft\Manganel\Helpers;
10
11
use Maslosoft\Gazebo\PluginFactory;
12
use Maslosoft\Manganel\Interfaces\QueryBuilder\BodyDecoratorInterface;
13
use Maslosoft\Manganel\Interfaces\QueryBuilder\ConditionsAwareInterface;
14
use Maslosoft\Manganel\Interfaces\QueryBuilder\DecoratorInterface;
15
use Maslosoft\Manganel\Manganel;
16
use Maslosoft\Manganel\SearchCriteria;
17
18
/**
19
 * QueryBuilderDecorator
20
 *
21
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
22
 */
23
class QueryBuilderDecorator
24
{
25
26
	/**
27
	 * Manganel instance
28
	 * @var Mangangel
29
	 */
30
	private $manganel = null;
31
32 7
	public function __construct(Manganel $manganel)
33
	{
34 7
		$this->manganel = $manganel;
0 ignored issues
show
Documentation Bug introduced by
It seems like $manganel of type object<Maslosoft\Manganel\Manganel> is incompatible with the declared type object<Maslosoft\Manganel\Helpers\Mangangel> of property $manganel.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
35 7
	}
36
37 7
	public function decorate(&$body, SearchCriteria $criteria)
38
	{
39 7
		$bodyDecorators = (new PluginFactory())->instance($this->manganel->decorators, $criteria, [
40
			BodyDecoratorInterface::class
41 7
		]);
42 7
		$conditionsDecorators = (new PluginFactory())->instance($this->manganel->decorators, $criteria, [
43
			DecoratorInterface::class
44 7
		]);
45
46 7
		$conditions = [];
47 7
		foreach ($conditionsDecorators as $decorator)
48
		{
49
			/* @var $decorator DecoratorInterface  */
50 7
			$decorator->decorate($conditions, $criteria);
51
		}
52
53 7
		foreach ($bodyDecorators as $decorator)
54
		{
55
			/* @var $decorator BodyDecoratorInterface  */
56 7
			if ($decorator instanceof ConditionsAwareInterface)
57
			{
58 7
				$decorator->setConditions($conditions);
59
			}
60 7
			$decorator->decorate($body, $criteria);
61
		}
62 7
	}
63
64
}
65