SingleModelDecorator::decorate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 9.7333
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3
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;
14
15
use Maslosoft\Gazebo\PluginFactory;
16
use Maslosoft\Mangan\Interfaces\ModelAwareInterface;
17
use Maslosoft\Mangan\Traits\ModelAwareTrait;
18
use Maslosoft\Manganel\Interfaces\ManganelAwareInterface;
19
use Maslosoft\Manganel\Interfaces\QueryBuilder\BodyDecoratorInterface;
20
use Maslosoft\Manganel\SearchCriteria;
21
use Maslosoft\Manganel\Traits\ManganelAwareTrait;
22
23
/**
24
 * SingleModelDecorator
25
 *
26
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
27
 */
28
class SingleModelDecorator implements ManganelAwareInterface
29
{
30
31
	use ManganelAwareTrait;
32
33 32
	public function decorate(&$body, SearchCriteria $criteria)
34
	{
35 32
		$decorators = (new PluginFactory())->instance($this->getManganel()->decorators, $criteria, [
36 32
			BodyDecoratorInterface::class
37
		]);
38
39 32
		foreach ($decorators as $decorator)
40
		{
41
			/* @var $decorator BodyDecoratorInterface  */
42 32
			if ($decorator instanceof ManganelAwareInterface)
43
			{
44 32
				$decorator->setManganel($this->manganel);
45
			}
46 32
			$decorator->decorate($body, $criteria);
47
		}
48 32
	}
49
50
}
51