Common   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Test Coverage

Coverage 96.49%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 10
dl 0
loc 127
ccs 55
cts 57
cp 0.9649
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A autorun() 0 8 1
A _setServer() 0 14 1
A _setClient() 0 18 1
A _setDriver() 0 16 4
A _setModule() 0 11 1
A _setPhp() 0 16 3
1
<?php
2
namespace Redaxscript\Bootstrap;
3
4
use PDO;
5
use Redaxscript\Client;
6
use Redaxscript\Server;
7
use function getenv;
8
use function is_dir;
9
use function strtolower;
10
use function version_compare;
11
12
/**
13
 * children class to boot the common
14
 *
15
 * @since 3.1.0
16
 *
17
 * @package Redaxscript
18
 * @category Bootstrap
19
 * @author Henry Ruhs
20
 */
21
22
class Common extends BootstrapAbstract
23
{
24
	/**
25
	 * automate run
26
	 *
27
	 * @since 3.1.0
28
	 */
29
30
	public function autorun() : void
31 7
	{
32
		$this->_setServer();
33 7
		$this->_setClient();
34 7
		$this->_setDriver();
35 7
		$this->_setModule();
36 7
		$this->_setPhp();
37 7
	}
38 7
39
	/**
40
	 * set the server
41
	 *
42
	 * @since 3.1.0
43
	 */
44
45
	protected function _setServer() : void
46 7
	{
47
		$file = new Server\File($this->_request);
48 7
		$root = new Server\Root($this->_request);
49 7
		$host = new Server\Host($this->_request);
50 7
		$token = new Server\Token($this->_request);
51 7
52
		/* set the registry */
53
54
		$this->_registry->set('file', $file->getOutput());
55 7
		$this->_registry->set('root', $root->getOutput());
56 7
		$this->_registry->set('host', $host->getOutput());
57 7
		$this->_registry->set('token', $token->getOutput());
58 7
	}
59 7
60
	/**
61
	 * set the client
62
	 *
63
	 * @since 3.1.0
64
	 */
65
66
	protected function _setClient() : void
67 7
	{
68
		$browser = new Client\Browser($this->_request);
69 7
		$version = new Client\Version($this->_request);
70 7
		$engine = new Client\Engine($this->_request);
71 7
		$mobile = new Client\Mobile($this->_request);
72 7
		$tablet = new Client\Tablet($this->_request);
73 7
		$desktop = new Client\Desktop($this->_request);
74 7
75
		/* set the registry */
76
77
		$this->_registry->set('myBrowser', $browser->getOutput());
78 7
		$this->_registry->set('myBrowserVersion', $version->getOutput());
79 7
		$this->_registry->set('myEngine', $engine->getOutput());
80 7
		$this->_registry->set('myMobile', $mobile->getOutput());
81 7
		$this->_registry->set('myTablet', $tablet->getOutput());
82 7
		$this->_registry->set('myDesktop', $desktop->getOutput());
83 7
	}
84 7
85
	/**
86
	 * set the driver
87
	 *
88
	 * @since 3.1.0
89
	 */
90
91
	protected function _setDriver() : void
92 7
	{
93
		$driverArray = [];
94 7
95
		/* process driver */
96
97
		foreach (PDO::getAvailableDrivers() as $driver)
98 7
		{
99
			$driver = $driver === 'sqlsrv' ? 'mssql' : $driver;
100 7
			if (is_dir('database' . DIRECTORY_SEPARATOR . $driver))
101 7
			{
102
				$driverArray[$driver] = $driver;
103 7
			}
104
		}
105
		$this->_registry->set('driverArray', $driverArray);
106 7
	}
107 7
108
	/**
109
	 * set the module
110
	 *
111
	 * @since 3.1.0
112
	 */
113
114
	protected function _setModule() : void
115 7
	{
116
		$this->_registry->set('moduleArray',
117 7
		[
118
			'mod_brotli' => getenv('REDIRECT_MOD_BROTLI') === 'on',
119 7
			'mod_deflate' => getenv('REDIRECT_MOD_DEFLATE') === 'on',
120 7
			'mod_security' => getenv('REDIRECT_MOD_SECURITY') === 'on',
121 7
			'mod_rewrite' => getenv('REDIRECT_MOD_REWRITE') === 'on',
122 7
			'mod_headers' => getenv('REDIRECT_MOD_HEADERS') === 'on'
123 7
		]);
124
	}
125 7
126
	/**
127
	 * set the php
128
	 *
129
	 * @since 4.3.0
130
	 */
131
132
	protected function _setPhp() : void
133 7
	{
134
		$phpOs = strtolower(PHP_OS_FAMILY);
135 7
		$phpVersion = PHP_VERSION;
136 7
		$this->_registry->set('phpOs', $phpOs);
137 7
		$this->_registry->set('phpVersion', $phpVersion);
138
		$this->_registry->set('phpStatus', 0);
139 7
		if (version_compare($phpVersion, '8.2', '>='))
140
		{
141
			$this->_registry->set('phpStatus', 1);
142
		}
143
		else if (version_compare($phpVersion, '8.0', '>='))
144
		{
145 7
			$this->_registry->set('phpStatus', 2);
146 7
		}
147 7
	}
148
}
149