| Total Complexity | 8 |
| Total Lines | 69 |
| Duplicated Lines | 0 % |
| Coverage | 92% |
| Changes | 7 | ||
| Bugs | 3 | Features | 0 |
| 1 | <?php |
||
| 7 | class DebugInfo |
||
| 8 | { |
||
| 9 | private $widget; |
||
| 10 | |||
| 11 | private $html; |
||
| 12 | |||
| 13 | private $policies; |
||
| 14 | |||
| 15 | 10 | public function __construct() |
|
| 16 | { |
||
| 17 | 10 | $this->policies = app(Policies::class); |
|
| 18 | 10 | } |
|
| 19 | |||
| 20 | /** |
||
| 21 | * @param object $widget |
||
| 22 | * @param string $html |
||
| 23 | * @return string |
||
| 24 | */ |
||
| 25 | 10 | public function addIdentifierToHtml($widget, string $html) |
|
| 26 | { |
||
| 27 | 10 | $this->widget = $widget; |
|
| 28 | 10 | $this->html = $html; |
|
| 29 | 10 | $this->addDebugInfo(); |
|
| 30 | 10 | $this->addHtmlComments(); |
|
| 31 | |||
| 32 | 10 | return $this->html; |
|
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Adds debug info to html as HTML title tags. |
||
| 37 | */ |
||
| 38 | 10 | private function addDebugInfo(): void |
|
| 39 | { |
||
| 40 | 10 | $tpl = $this->getTplPath($this->widget->template); |
|
| 41 | |||
| 42 | 10 | $this->html = "<span title='WidgetObj : ".get_class($this->widget).".php
Template : {$tpl}{$this->cacheState()}'>{$this->html}</span>"; |
|
| 43 | 10 | } |
|
| 44 | |||
| 45 | /** |
||
| 46 | * Generates a string of current cache configurations. |
||
| 47 | * |
||
| 48 | * @return string |
||
| 49 | */ |
||
| 50 | 10 | private function cacheState() |
|
| 51 | { |
||
| 52 | 10 | if (! $this->policies->widgetShouldUseCache()) { |
|
| 53 | 10 | return ' 
 Cache: is globally turned off (You should put "enable_cache" => true in config\widgetize.php) '; |
|
| 54 | } |
||
| 55 | $l = $this->widget->cacheLifeTime->i ?? 0; |
||
| 56 | |||
| 57 | return " 
Cache : {$l} (min) "; |
||
| 58 | } |
||
| 59 | |||
| 60 | 10 | private function addHtmlComments(): void |
|
| 63 | 10 | } |
|
| 64 | |||
| 65 | /** |
||
| 66 | * @param string $tpl |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | 10 | private function getTplPath(string $tpl) |
|
| 76 | } |
||
| 77 | } |
||
| 78 |