Completed
Push — master ( db6b00...5246ee )
by
unknown
08:09 queued 11s
created

TermboxFlag::shouldRenderTermboxDesktop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Wikibase\Repo\ParserOutput;
4
5
use ExtensionRegistry;
6
use MobileContext;
7
use Wikibase\Lib\SettingsArray;
8
use Wikibase\Repo\WikibaseRepo;
9
10
/**
11
 * @license GPL-2.0-or-later
12
 */
13
class TermboxFlag {
14
15
	private $settings;
16
17
	private $extensionRegistry;
18
19
	public const TERMBOX_FLAG = 'termboxEnabled';
20
	public const TERMBOX_DESKTOP_FLAG = 'termboxDesktopEnabled';
21
22
	public function __construct(
23
		SettingsArray $settings,
24
		ExtensionRegistry $extensionRegistry
25
	) {
26
		$this->settings = $settings;
27
		$this->extensionRegistry = $extensionRegistry;
28
	}
29
30
	public static function getInstance() {
31
		return new self(
32
			WikibaseRepo::getDefaultInstance()->getSettings(),
33
			ExtensionRegistry::getInstance()
34
		);
35
	}
36
37
	/**
38
	 * Determines whether the Termbox should be rendered
39
	 *
40
	 * @return bool
41
	 */
42
	public function shouldRenderTermbox() {
43
		return (
44
			$this->isMobile() && $this->shouldRenderTermboxMobile() ||
45
			!$this->isMobile() && $this->shouldRenderTermboxDesktop()
46
		);
47
	}
48
49
	private function shouldRenderTermboxMobile(): bool {
50
		return $this->settings->getSetting( self::TERMBOX_FLAG );
51
	}
52
53
	private function isMobile(): bool {
54
		return $this->extensionRegistry->isLoaded( 'MobileFrontend' )
55
			&& MobileContext::singleton()->shouldDisplayMobileView();
56
	}
57
58
	private function shouldRenderTermboxDesktop(): bool {
59
		return $this->settings->getSetting( self::TERMBOX_DESKTOP_FLAG );
60
	}
61
62
}
63