Completed
Push — master ( 6008be...02cb07 )
by Daniel
32s queued 13s
created
lib/OperatingSystems/DefaultOs.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 			return $data;
46 46
 		}
47 47
 
48
-		$matches = [];
48
+		$matches = [ ];
49 49
 		$pattern = '/(?<Key>(?:MemTotal|MemFree|MemAvailable|SwapTotal|SwapFree)+):\s+(?<Value>\d+)\s+(?<Unit>\w{2})/';
50 50
 
51 51
 		$result = preg_match_all($pattern, $meminfo, $matches);
@@ -53,9 +53,9 @@  discard block
 block discarded – undo
53 53
 			return $data;
54 54
 		}
55 55
 
56
-		foreach ($matches['Key'] as $i => $key) {
56
+		foreach ($matches[ 'Key' ] as $i => $key) {
57 57
 			// Value is always in KB: https://github.com/torvalds/linux/blob/c70672d8d316ebd46ea447effadfe57ab7a30a50/fs/proc/meminfo.c#L58-L60
58
-			$value = (int)((int)$matches['Value'][$i] / 1024);
58
+			$value = (int) ((int) $matches[ 'Value' ][ $i ] / 1024);
59 59
 
60 60
 			switch ($key) {
61 61
 				case 'MemTotal':
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 			return $data;
89 89
 		}
90 90
 
91
-		$matches = [];
91
+		$matches = [ ];
92 92
 
93 93
 		if (str_contains($cpuinfo, 'Raspberry Pi')) {
94 94
 			$pattern = '/Model\s+:\s(.+)/';
@@ -101,24 +101,24 @@  discard block
 block discarded – undo
101 101
 			return $data;
102 102
 		}
103 103
 
104
-		$model = $matches[1][0];
104
+		$model = $matches[ 1 ][ 0 ];
105 105
 
106 106
 		$pattern = '/processor\s+:\s(.+)/';
107 107
 
108 108
 		preg_match_all($pattern, $cpuinfo, $matches);
109
-		$cores = count($matches[1]);
109
+		$cores = count($matches[ 1 ]);
110 110
 
111 111
 		if ($cores === 1) {
112
-			$data = $model . ' (1 core)';
112
+			$data = $model.' (1 core)';
113 113
 		} else {
114
-			$data = $model . ' (' . $cores . ' cores)';
114
+			$data = $model.' ('.$cores.' cores)';
115 115
 		}
116 116
 
117 117
 		return $data;
118 118
 	}
119 119
 
120 120
 	public function getTime(): string {
121
-		return (string)shell_exec('date');
121
+		return (string) shell_exec('date');
122 122
 	}
123 123
 
124 124
 	public function getUptime(): int {
@@ -130,35 +130,35 @@  discard block
 block discarded – undo
130 130
 			return $data;
131 131
 		}
132 132
 
133
-		[$uptimeInSeconds,] = array_map('intval', explode(' ', $uptime));
133
+		[ $uptimeInSeconds, ] = array_map('intval', explode(' ', $uptime));
134 134
 
135 135
 		return $uptimeInSeconds;
136 136
 	}
137 137
 
138 138
 	public function getNetworkInfo(): array {
139
-		$result = [];
140
-		$result['hostname'] = \gethostname();
139
+		$result = [ ];
140
+		$result[ 'hostname' ] = \gethostname();
141 141
 		$dns = shell_exec('cat /etc/resolv.conf |grep -i \'^nameserver\'|head -n1|cut -d \' \' -f2');
142
-		$result['dns'] = $dns;
142
+		$result[ 'dns' ] = $dns;
143 143
 		$gw = shell_exec('ip route | awk \'/default/ { print $3 }\'');
144
-		$result['gateway'] = $gw;
144
+		$result[ 'gateway' ] = $gw;
145 145
 		return $result;
146 146
 	}
147 147
 
148 148
 	public function getNetworkInterfaces(): array {
149
-		$data = [];
149
+		$data = [ ];
150 150
 
151 151
 		foreach ($this->getNetInterfaces() as $interfaceName => $interface) {
152
-			$netInterface = new NetInterface($interfaceName, $interface['up']);
153
-			$data[] = $netInterface;
152
+			$netInterface = new NetInterface($interfaceName, $interface[ 'up' ]);
153
+			$data[ ] = $netInterface;
154 154
 
155
-			foreach ($interface['unicast'] as $unicast) {
156
-				if (isset($unicast['family'])) {
157
-					if ($unicast['family'] === self::AF_INET) {
158
-						$netInterface->addIPv4($unicast['address']);
155
+			foreach ($interface[ 'unicast' ] as $unicast) {
156
+				if (isset($unicast[ 'family' ])) {
157
+					if ($unicast[ 'family' ] === self::AF_INET) {
158
+						$netInterface->addIPv4($unicast[ 'address' ]);
159 159
 					}
160
-					if ($unicast['family'] === self::AF_INET6) {
161
-						$netInterface->addIPv6($unicast['address']);
160
+					if ($unicast[ 'family' ] === self::AF_INET6) {
161
+						$netInterface->addIPv6($unicast[ 'address' ]);
162 162
 					}
163 163
 				}
164 164
 			}
@@ -167,19 +167,19 @@  discard block
 block discarded – undo
167 167
 				continue;
168 168
 			}
169 169
 
170
-			$interfacePath = '/sys/class/net/' . $interfaceName;
170
+			$interfacePath = '/sys/class/net/'.$interfaceName;
171 171
 
172 172
 			try {
173
-				$netInterface->setMAC($this->readContent($interfacePath . '/address'));
173
+				$netInterface->setMAC($this->readContent($interfacePath.'/address'));
174 174
 
175
-				$speed = (int)$this->readContent($interfacePath . '/speed');
175
+				$speed = (int) $this->readContent($interfacePath.'/speed');
176 176
 				if ($speed >= 1000) {
177
-					$netInterface->setSpeed($speed / 1000 . ' Gbps');
177
+					$netInterface->setSpeed($speed / 1000.' Gbps');
178 178
 				} else {
179
-					$netInterface->setSpeed($speed . ' Mbps');
179
+					$netInterface->setSpeed($speed.' Mbps');
180 180
 				}
181 181
 
182
-				$netInterface->setDuplex($this->readContent($interfacePath . '/duplex'));
182
+				$netInterface->setDuplex($this->readContent($interfacePath.'/duplex'));
183 183
 			} catch (RuntimeException $e) {
184 184
 				// unable to read interface data
185 185
 			}
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	}
190 190
 
191 191
 	public function getDiskInfo(): array {
192
-		$data = [];
192
+		$data = [ ];
193 193
 
194 194
 		try {
195 195
 			$disks = $this->executeCommand('df -TPk');
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 			return $data;
198 198
 		}
199 199
 
200
-		$matches = [];
200
+		$matches = [ ];
201 201
 		$pattern = '/^(?<Filesystem>[\S]+)\s*(?<Type>[\S]+)\s*(?<Blocks>\d+)\s*(?<Used>\d+)\s*(?<Available>\d+)\s*(?<Capacity>\d+%)\s*(?<Mounted>[\w\/-]+)$/m';
202 202
 
203 203
 		$result = preg_match_all($pattern, $disks, $matches);
@@ -205,41 +205,41 @@  discard block
 block discarded – undo
205 205
 			return $data;
206 206
 		}
207 207
 
208
-		foreach ($matches['Filesystem'] as $i => $filesystem) {
209
-			if (in_array($matches['Type'][$i], ['tmpfs', 'devtmpfs', 'squashfs', 'overlay'], false)) {
208
+		foreach ($matches[ 'Filesystem' ] as $i => $filesystem) {
209
+			if (in_array($matches[ 'Type' ][ $i ], [ 'tmpfs', 'devtmpfs', 'squashfs', 'overlay' ], false)) {
210 210
 				continue;
211
-			} elseif (in_array($matches['Mounted'][$i], ['/etc/hostname', '/etc/hosts'], false)) {
211
+			} elseif (in_array($matches[ 'Mounted' ][ $i ], [ '/etc/hostname', '/etc/hosts' ], false)) {
212 212
 				continue;
213 213
 			}
214 214
 
215 215
 			$disk = new Disk();
216 216
 			$disk->setDevice($filesystem);
217
-			$disk->setFs($matches['Type'][$i]);
218
-			$disk->setUsed((int)((int)$matches['Used'][$i] / 1024));
219
-			$disk->setAvailable((int)((int)$matches['Available'][$i] / 1024));
220
-			$disk->setPercent($matches['Capacity'][$i]);
221
-			$disk->setMount($matches['Mounted'][$i]);
217
+			$disk->setFs($matches[ 'Type' ][ $i ]);
218
+			$disk->setUsed((int) ((int) $matches[ 'Used' ][ $i ] / 1024));
219
+			$disk->setAvailable((int) ((int) $matches[ 'Available' ][ $i ] / 1024));
220
+			$disk->setPercent($matches[ 'Capacity' ][ $i ]);
221
+			$disk->setMount($matches[ 'Mounted' ][ $i ]);
222 222
 
223
-			$data[] = $disk;
223
+			$data[ ] = $disk;
224 224
 		}
225 225
 
226 226
 		return $data;
227 227
 	}
228 228
 
229 229
 	public function getThermalZones(): array {
230
-		$thermalZones = glob('/sys/class/thermal/thermal_zone*') ?: [];
231
-		$result = [];
230
+		$thermalZones = glob('/sys/class/thermal/thermal_zone*') ?: [ ];
231
+		$result = [ ];
232 232
 
233 233
 		foreach ($thermalZones as $thermalZone) {
234
-			$tzone = [];
234
+			$tzone = [ ];
235 235
 			try {
236
-				$tzone['hash'] = md5($thermalZone);
237
-				$tzone['type'] = $this->readContent($thermalZone . '/type');
238
-				$tzone['temp'] = (float)((int)($this->readContent($thermalZone . '/temp')) / 1000);
236
+				$tzone[ 'hash' ] = md5($thermalZone);
237
+				$tzone[ 'type' ] = $this->readContent($thermalZone.'/type');
238
+				$tzone[ 'temp' ] = (float) ((int) ($this->readContent($thermalZone.'/temp')) / 1000);
239 239
 			} catch (RuntimeException $e) {
240 240
 				continue;
241 241
 			}
242
-			$result[] = $tzone;
242
+			$result[ ] = $tzone;
243 243
 		}
244 244
 
245 245
 		return $result;
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	protected function readContent(string $filename): string {
252 252
 		$data = @file_get_contents($filename);
253 253
 		if ($data === false || $data === '') {
254
-			throw new RuntimeException('Unable to read: "' . $filename . '"');
254
+			throw new RuntimeException('Unable to read: "'.$filename.'"');
255 255
 		}
256 256
 		return trim($data);
257 257
 	}
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	protected function executeCommand(string $command): string {
260 260
 		$output = @shell_exec(escapeshellcmd($command));
261 261
 		if ($output === false || $output === null || $output === '') {
262
-			throw new RuntimeException('No output for command: "' . $command . '"');
262
+			throw new RuntimeException('No output for command: "'.$command.'"');
263 263
 		}
264 264
 		return $output;
265 265
 	}
Please login to merge, or discard this patch.