Completed
Push — master ( 5a683a...37dbab )
by Peter
09:05
created

SingleModelDecorator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A decorate() 0 16 3
1
<?php
2
3
namespace Maslosoft\Manganel\Decorators\QueryBuilder;
4
5
use Maslosoft\Gazebo\PluginFactory;
6
use Maslosoft\Mangan\Interfaces\ModelAwareInterface;
7
use Maslosoft\Mangan\Traits\ModelAwareTrait;
8
use Maslosoft\Manganel\Interfaces\ManganelAwareInterface;
9
use Maslosoft\Manganel\Interfaces\QueryBuilder\BodyDecoratorInterface;
10
use Maslosoft\Manganel\SearchCriteria;
11
use Maslosoft\Manganel\Traits\ManganelAwareTrait;
12
13
/**
14
 * SingleModelDecorator
15
 *
16
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
17
 */
18
class SingleModelDecorator implements ManganelAwareInterface,
19
		ModelAwareInterface
20
{
21
22
	use ManganelAwareTrait,
23
	  ModelAwareTrait;
24
25 42
	public function __construct($model)
26
	{
27 42
		$this->model = $model;
28 42
	}
29
30 42
	public function decorate(&$body, SearchCriteria $criteria)
31
	{
32 42
		$decorators = (new PluginFactory())->instance($this->getManganel()->decorators, $criteria, [
33
			BodyDecoratorInterface::class
34 42
		]);
35
36 42
		foreach ($decorators as $decorator)
37
		{
38
			/* @var $decorator BodyDecoratorInterface  */
39 42
			if ($decorator instanceof ManganelAwareInterface)
40
			{
41 42
				$decorator->setManganel($this->manganel);
42
			}
43 42
			$decorator->decorate($body, $criteria);
44
		}
45 42
	}
46
47
}
48