TranslatorPanel   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTab() 0 9 3
A setResolvers() 0 4 1
A getPanel() 0 19 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Nette extension for bckp/translator
7
 * (c) Radovan Kepák
8
 *
9
 * For the full copyright and license information, please view the file license.md that was distributed with this source code.
10
 *
11
 * @author Radovan Kepak <[email protected]>
12
 *  --------------------------------------------------------------------------
13
 */
14
15
namespace Bckp\Translator\Nette\Diagnostics;
16
17
use Bckp\Translator\Diagnostics\Diagnostics;
18
use Bckp\Translator\Nette\Resolvers\LocaleResolver;
19
use Psalm\Issue\UnusedVariable;
20
use Tracy\IBarPanel;
21
use Nette\Utils\Helpers;
22
23
use function count;
24
use function strtoupper;
25
26
final class TranslatorPanel extends Diagnostics implements IBarPanel
27
{
28
	/** @var LocaleResolver[] */
29
	private array $resolvers = [];
30
31
	/** @var string[] */
32
	private array $languages = [];
33
34
	/**
35
	 * @api
36
	 * @param string[] $languages
37
	 */
38
	public function setResolvers(array $languages, LocaleResolver ...$resolvers): void
39
	{
40
		$this->languages = $languages;
41
		$this->resolvers = $resolvers;
42
	}
43
44
	#[\Override]
45
	public function getTab(): string
46
	{
47
		/** @psalm-suppress UnusedVariable */
48
		return Helpers::capture(function () {
49
			$color = !empty($this->getWarnings()) || !empty($this->getUntranslated()) ? 'B71C1C' : '009688';
50
			$locale = strtoupper($this->getLocale());
51
52
			require __DIR__ . '/dist/tab.phtml';
53
		});
54
	}
55
56
	#[\Override]
57
	public function getPanel(): string
58
	{
59
		/** @psalm-suppress UnusedVariable */
60
		return Helpers::capture(function () {
61
			$locale = strtoupper($this->getLocale());
62
63
			$errors = $this->getWarnings();
64
			$countErrors = count($errors);
65
			$hasErrors = $countErrors > 0;
66
67
			$untranslated = $this->getUntranslated();
68
			$countUntranslated = count($untranslated);
69
			$hasUntranslated = $countUntranslated > 0;
70
71
			$resolvers = $this->resolvers;
72
			$languages = $this->languages;
73
74
			require __DIR__ . '/dist/panel.phtml';
75
		});
76
	}
77
}
78