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

TermboxFlag   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getInstance() 0 6 1
A shouldRenderTermbox() 0 6 4
A shouldRenderTermboxMobile() 0 3 1
A isMobile() 0 4 2
A shouldRenderTermboxDesktop() 0 3 1
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