QueryBuilderDecorator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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\Helpers;
14
15
use Maslosoft\Manganel\Decorators\QueryBuilder\MultiModelDecorator;
16
use Maslosoft\Manganel\Decorators\QueryBuilder\SingleModelDecorator;
17
use Maslosoft\Manganel\Interfaces\ModelsAwareInterface;
18
use Maslosoft\Manganel\Manganel;
19
use Maslosoft\Manganel\SearchCriteria;
20
use Maslosoft\Manganel\Traits\UniqueModelsAwareTrait;
21
22
/**
23
 * QueryBuilderDecorator
24
 *
25
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
26
 */
27
class QueryBuilderDecorator implements ModelsAwareInterface
28
{
29
30
	use UniqueModelsAwareTrait;
31
32
	/**
33
	 * Manganel instance
34
	 * @var Manganel
35
	 */
36
	private $manganel = null;
37
38 32
	public function __construct(Manganel $manganel)
39
	{
40 32
		$this->manganel = $manganel;
41 32
	}
42
43 32
	public function decorate(&$body, SearchCriteria $criteria)
44
	{
45
46 32
		$models = $this->getModels();
47 32
		$numModels = count($models);
48
49 32
		if ($numModels === 1)
50
		{
51 26
			(new SingleModelDecorator())
52 26
					->setManganel($this->manganel)
53 26
					->decorate($body, $criteria);
54
		}
55
		else
56
		{
57 6
			(new MultiModelDecorator($models))
58 6
					->setManganel($this->manganel)
59 6
					->decorate($body, $criteria);
60
		}
61 32
	}
62
63
}
64