Client   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 86
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 15 2
A _getBrowserArray() 0 9 1
A _getDeviceArray() 0 31 4
1
<?php
2
namespace Redaxscript\Template\Helper;
3
4
use function array_filter;
5
use function array_merge;
6
use function array_unique;
7
use function implode;
8
9
/**
10
 * helper class to provide a client helper
11
 *
12
 * @since 3.0.0
13
 *
14
 * @package Redaxscript
15
 * @category Template
16
 * @author Henry Ruhs
17
 */
18
19
class Client extends HelperAbstract
20
{
21
	/**
22
	 * process
23
	 *
24
	 * @since 3.0.0
25
	 *
26
	 * @param string $prefix
27
	 *
28
	 * @return string|null
29
	 */
30
31 4
	public function process(string $prefix = null) : ?string
32
	{
33 4
		$clientArray = array_unique(array_merge(
34 4
			$this->_getBrowserArray(),
35 4
			$this->_getDeviceArray()
36
		));
37
38
		/* process client */
39
40 4
		foreach ($clientArray as $key => $value)
41
		{
42 3
			$clientArray[$key] = $prefix . $value;
43
		}
44 4
		return implode(' ', $clientArray);
45
	}
46
47
	/**
48
	 * get the browser array
49
	 *
50
	 * @since 3.0.0
51
	 *
52
	 * @return array
53
	 */
54
55 4
	protected function _getBrowserArray() : array
56
	{
57 4
		return array_filter(
58
		[
59 4
			$this->_registry->get('myBrowser'),
60 4
			$this->_registry->get('myBrowserVersion'),
61 4
			$this->_registry->get('myEngine')
62
		]);
63
	}
64
65
	/**
66
	 * get the device array
67
	 *
68
	 * @since 3.0.0
69
	 *
70
	 * @return array
71
	 */
72
73 4
	protected function _getDeviceArray() : array
74
	{
75 4
		$myMobile = $this->_registry->get('myMobile');
76 4
		$myTablet = $this->_registry->get('myTablet');
77 4
		$myDesktop = $this->_registry->get('myDesktop');
78 4
		if ($myMobile)
79
		{
80
			return
81
			[
82 1
				'mobile',
83 1
				$myMobile
84
			];
85
		}
86 3
		if ($myTablet)
87
		{
88
			return
89
			[
90 1
				'tablet',
91 1
				$myTablet
92
			];
93
		}
94 2
		if ($myDesktop)
95
		{
96
			return
97
			[
98 1
				'desktop',
99 1
				$myDesktop
100
			];
101
		}
102 1
		return [];
103
	}
104
}
105