Decorator::render()   B
last analyzed

Complexity

Conditions 6
Paths 11

Size

Total Lines 29
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 0
cts 11
cp 0
rs 8.439
c 0
b 0
f 0
cc 6
eloc 12
nc 11
nop 1
crap 42
1
<?php
2
/**
3
 * Decorator.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        https://www.ipublikuj.eu
7
 * @author         Adam Kadlec <[email protected]>
8
 * @package        iPublikuj:Widgets!
9
 * @subpackage     Decorators
10
 * @since          1.0.0
11
 *
12
 * @date           18.06.15
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\Widgets\Decorators;
18
19
use Nette\Application;
20
use Nette\Bridges;
21
use Nette\Localization;
22
23
use IPub\Widgets;
24
use IPub\Widgets\Decorators;
25
use IPub\Widgets\Exceptions;
26
27
/**
28
 * Widgets base decorator control definition
29
 *
30
 * @package        iPublikuj:Widgets!
31
 * @subpackage     Decorators
32
 *
33
 * @author         Adam Kadlec <[email protected]>
34
 *
35
 * @property Application\UI\ITemplate $template
36
 */
37 1
abstract class Decorator extends Widgets\Application\UI\BaseControl implements Decorators\IDecorator
38
{
39
	/**
40
	 * {@inheritdoc}
41
	 */
42
	public function render(Widgets\Widgets\IWidget $widget) : void
43
	{
44
		// Check if control has template
45
		if ($this->template instanceof Bridges\ApplicationLatte\Template) {
0 ignored issues
show
Bug introduced by
The class Nette\Bridges\ApplicationLatte\Template does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
46
			// Assign vars to template
47
			$this->template->widget = $widget;
48
49
			// Check if translator is available
50
			if ($this->getTranslator() instanceof Localization\ITranslator) {
0 ignored issues
show
Bug introduced by
The class Nette\Localization\ITranslator does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
51
				$this->template->setTranslator($this->getTranslator());
52
			}
53
54
			// If template was not defined before...
55
			if ($this->template->getFile() === NULL) {
56
				// Get component actual dir
57
				$dir = dirname($this->getReflection()->getFileName());
58
59
				// ...try to get base component template file
60
				$templateFile = $this->templateFile !== NULL && is_file($this->templateFile) ? $this->templateFile : $dir . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . 'default.latte';
61
				$this->template->setFile($templateFile);
62
			}
63
64
			// Render component template
65
			$this->template->render();
66
67
		} else {
68
			throw new Exceptions\InvalidStateException('Widgets decorator control is without template.');
69
		}
70
	}
71
}
72