TranslationPanel::getTab()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 5
rs 10
ccs 3
cts 3
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Nexendrie\Translation\Bridges\Tracy;
5
6
use Nexendrie\Translation\ILoader;
7
use Nexendrie\Translation\Translator;
8
use Tracy\IBarPanel;
9
10
/**
11
 * Debugger panel for Tracy
12
 *
13
 * @author Jakub Konečný
14
 */
15 1
final class TranslationPanel implements IBarPanel {
16
  private Translator $translator;
17
  private ILoader $loader;
18
  
19
  public function __construct(Translator $translator, ILoader $loader) {
20 1
    $this->translator = $translator;
21 1
    $this->loader = $loader;
22 1
  }
23
  
24
  public function getTab(): string {
25 1
    $lang = $this->loader->getLang();
26
    /** @var string $tab */
27 1
    $tab = file_get_contents(__DIR__ . "/TranslationPanel.tab.html");
28 1
    return str_replace("%lang%", $lang, $tab);
29
  }
30
  
31
  public function getPanel(): string {
32 1
    $loader = $this->loader;
33 1
    $translator = $this->translator;
34 1
    $resourcesCount = count($loader->getResources(), COUNT_RECURSIVE) - count($loader->getResources());
35 1
    ob_start();
36 1
    require __DIR__ . "/TranslationPanel.panel.phtml";
37 1
    return (string) ob_get_clean();
38
  }
39
  
40
  protected function renderLink(string $resource): string {
41 1
    if(is_file($resource)) {
42 1
      return \Tracy\Helpers::editorLink($resource);
43
    }
44
    return $resource;
45
  }
46
}
47
?>