Panel   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 106
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getTab() 0 8 1
A getPanel() 0 43 4
A getIcon() 0 6 1
A getStyles() 0 15 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SixtyEightPublishers\Application\Environment\Diagnostics;
6
7
use Nette\Utils\Html;
8
use SixtyEightPublishers\Application\Environment\Environment;
9
use SixtyEightPublishers\Application\Environment\Profile;
10
use SixtyEightPublishers\Application\Environment\ProfileContainer;
11
use Tracy\IBarPanel;
12
13
class Panel implements IBarPanel
14
{
15
	/** @var \SixtyEightPublishers\Application\Environment\ProfileContainer  */
16
	private $profiles;
17
18
	/** @var \SixtyEightPublishers\Application\Environment\Environment  */
19
	private $environment;
20
21
	/**
22
	 * @param \SixtyEightPublishers\Application\Environment\ProfileContainer    $profiles
23
	 * @param \SixtyEightPublishers\Application\Environment\Environment         $environment
24
	 */
25
	public function __construct(ProfileContainer $profiles, Environment $environment)
26
	{
27
		$this->profiles = $profiles;
28
		$this->environment = $environment;
29
	}
30
31
	/**
32
	 * @return string
33
	 */
34
	public function getTab()
35
	{
36
		return (string) Html::el('span title="Environment"')
37
			->addHtml($this->getIcon())
38
			->addHtml(
39
				Html::el('span class=tracy-label')->setText($this->environment->getProfile()->getName())
40
		);
41
	}
42
43
	/**
44
	 * @return string
45
	 */
46
	public function getPanel()
47
	{
48
		$panel = [];
49
		$panel[] = Html::el('h2')->setText('Configured profiles:');
50
51
		$table = Html::el('table');
52
		$table->addHtml(Html::el('thead')->addHtml(
53
			Html::el('tr')
54
			->addHtml(Html::el('th'))
55
			->addHtml(Html::el('th')->setText('name'))
56
			->addHtml(Html::el('th')->setText('country'))
57
			->addHtml(Html::el('th')->setText('language'))
58
			->addHtml(Html::el('th')->setText('currency'))
59
			->addHtml(Html::el('th')->setText('domain'))
60
		));
61
		$table->addHtml($tbody = Html::el('tbody'));
62
63
		/** @var Profile $profile */
64
		foreach ($this->profiles as $profile) {
65
			$tbody->addHtml(
66
				$tr = Html::el('tr')
67
				->addHtml($firstCell = Html::el('td'))
68
				->addHtml(Html::el('td')->setText($profile->getName()))
69
				->addHtml(Html::el('td')->setHtml(implode('<br>', $profile->getCountries())))
70
				->addHtml(Html::el('td')->setHtml(implode('<br>', $profile->getLanguages())))
71
				->addHtml(Html::el('td')->setHtml(implode('<br>', $profile->getCurrencies())))
72
				->addHtml(Html::el('td')->setHtml(implode('<br>', $profile->getDomains())))
73
			);
74
75
			if ($profile->getName() === $this->environment->getProfile()->getName()) {
76
				$tr->class[] = 'yes';
77
				$firstCell->setText('✓');
78
			} elseif (!$profile->isEnabled()) {
79
				$tr->class[] = 'disabled';
80
				$firstCell->setText('✗');
81
			}
82
		}
83
84
		$panel[] = $table;
85
		$h1 = Html::el('h1')->setText('Environment');
86
87
		return $h1 . Html::el('div class="nette-inner tracy-inner sixtyEightPublishers-EnvironmentPanel"')->setHtml(implode(' ', $panel)) . $this->getStyles();
88
	}
89
90
	/**
91
	 * @return string
92
	 */
93
	private function getIcon()
94
	{
95
		return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="2 2 28 28">
96
			<path fill="#007CFF" d="M16 4c-6.627 0-12 5.373-12 12s5.373 12 12 12c0.811 0 1.603-0.081 2.369-0.234-0.309-0.148-0.342-1.255-0.037-1.887 0.34-0.703 1.406-2.484 0.352-3.082s-0.762-0.867-1.406-1.559-0.381-0.795-0.422-0.973c-0.141-0.609 0.621-1.523 0.656-1.617s0.035-0.445 0.023-0.551-0.48-0.387-0.598-0.398-0.176 0.188-0.34 0.199-0.879-0.434-1.031-0.551-0.223-0.398-0.434-0.609-0.234-0.047-0.563-0.176-1.383-0.516-2.191-0.844-0.879-0.788-0.891-1.113-0.492-0.797-0.718-1.137c-0.225-0.34-0.267-0.809-0.349-0.703s0.422 1.336 0.34 1.371-0.258-0.34-0.492-0.645 0.246-0.141-0.504-1.617 0.234-2.229 0.281-3 0.633 0.281 0.328-0.211 0.023-1.523-0.211-1.898-1.57 0.422-1.57 0.422c0.035-0.363 1.172-0.984 1.992-1.559s1.321-0.129 1.98 0.082 0.703 0.141 0.48-0.070 0.094-0.316 0.609-0.234 0.656 0.703 1.441 0.645 0.082 0.152 0.188 0.352-0.117 0.176-0.633 0.527 0.012 0.352 0.926 1.020 0.633-0.445 0.539-0.938 0.668-0.105 0.668-0.105c0.563 0.375 0.459 0.021 0.869 0.15s1.522 1.069 1.522 1.069c-1.395 0.762-0.516 0.844-0.281 1.020s-0.48 0.516-0.48 0.516c-0.293-0.293-0.34 0.012-0.527 0.117s-0.012 0.375-0.012 0.375c-0.97 0.152-0.75 1.172-0.738 1.418s-0.621 0.621-0.785 0.973 0.422 1.113 0.117 1.16-0.609-1.148-2.25-0.703c-0.495 0.134-1.594 0.703-1.008 1.863s1.559-0.328 1.887-0.164-0.094 0.902-0.023 0.914 0.926 0.032 0.973 1.031 1.301 0.914 1.57 0.938 1.172-0.738 1.301-0.773 0.645-0.469 1.77 0.176 1.699 0.551 2.086 0.82 0.117 0.809 0.48 0.984 1.816-0.059 2.18 0.539-1.5 3.598-2.086 3.926-0.855 1.078-1.441 1.559-1.406 1.075-2.18 1.535c-0.685 0.407-0.808 1.136-1.113 1.367 5.37-1.193 9.386-5.985 9.386-11.714 0-6.627-5.373-12-12-12zM18.813 15.262c-0.164 0.047-0.504 0.352-1.336-0.141s-1.406-0.398-1.477-0.48c0 0-0.070-0.199 0.293-0.234 0.746-0.072 1.688 0.691 1.898 0.703s0.316-0.211 0.691-0.090c0.375 0.121 0.094 0.196-0.070 0.242zM14.887 5.195c-0.082-0.059 0.068-0.128 0.157-0.246 0.051-0.068 0.013-0.182 0.078-0.246 0.176-0.176 1.043-0.422 0.873 0.059s-0.979 0.527-1.108 0.434zM16.984 6.719c-0.293-0.012-0.983-0.085-0.855-0.211 0.495-0.492-0.188-0.633-0.609-0.668s-0.598-0.27-0.387-0.293 1.055 0.012 1.195 0.129 0.902 0.422 0.949 0.645 0 0.41-0.293 0.398zM19.527 6.637c-0.234 0.188-1.414-0.673-1.641-0.867-0.984-0.844-1.512-0.563-1.718-0.703s-0.133-0.328 0.183-0.609 1.207 0.094 1.723 0.152 1.113 0.457 1.125 0.931c0.012 0.474 0.563 0.909 0.328 1.097z"></path>
97
		</svg>';
98
	}
99
100
	/**
101
	 * @return string
102
	 */
103
	private function getStyles()
104
	{
105
		return "<style>
106
			#nette-debug .sixtyEightPublishers-EnvironmentPanel h2, #tracy-debug .sixtyEightPublishers-EnvironmentPanel h2 {
107
				font-size: 14px;
108
			}
109
			#nette-debug .sixtyEightPublishers-EnvironmentPanel tr.yes td, #tracy-debug .sixtyEightPublishers-EnvironmentPanel tr.yes td {
110
				background: #BDE678;
111
			}
112
			#nette-debug .sixtyEightPublishers-EnvironmentPanel tr.disabled td, #tracy-debug .sixtyEightPublishers-EnvironmentPanel tr.disabled td {
113
				background: #DDD;
114
				color: #888;
115
			}
116
		</style>";
117
	}
118
}
119