TemplateFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 38
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A create() 0 9 2
A setVariables() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace h4kuna\MailManager\Template;
4
5
use Nette\Application;
6
use Nette\Bridges\ApplicationLatte;
7
8
class TemplateFactory implements ITemplateFactory
9
{
10
11
	/** @var Application\UI\ITemplateFactory */
12
	private $templateFactory;
13
14
	/** @var Application\LinkGenerator */
15
	private $linkGenerator;
16
17
	/** @var mixed[] */
18
	private $variables = [];
19
20
21
	public function __construct(
22
		Application\UI\ITemplateFactory $templateFactory,
23
		Application\LinkGenerator $linkGenerator
24
	)
25
	{
26
		$this->templateFactory = $templateFactory;
27
		$this->linkGenerator = $linkGenerator;
28
	}
29
30
31
	public function setVariables(array $variables): void
32
	{
33
		$this->variables = $variables;
34
	}
35
36
37
	public function create(): Application\UI\ITemplate
38
	{
39
		/** @var ApplicationLatte\Template $template */
40
		$template = $this->templateFactory->createTemplate();
41
		$template->getLatte()->addProvider('uiControl', $this->linkGenerator);
42
		foreach ($this->variables as $name => $value) {
43
			$template->{$name} = $value;
44
		}
45
		return $template;
46
	}
47
48
}
49