@@ -21,28 +21,19 @@ class SystemCheckCommand extends Command
2121{
2222 private const NODE_LTS_URL = 'https://nodejs.org/dist/index.json ' ;
2323
24- /**
25- * @inheritDoc
26- */
2724 public function __construct (
2825 private readonly ProductMetadataInterface $ productMetadata ,
2926 private readonly Escaper $ escaper ,
3027 ) {
3128 parent ::__construct ();
3229 }
3330
34- /**
35- * @inheritDoc
36- */
3731 protected function configure (): void
3832 {
3933 $ this ->setName ('mageforge:system:check ' );
4034 $ this ->setDescription ('Displays system information like PHP version and Node.js version ' );
4135 }
4236
43- /**
44- * @inheritDoc
45- */
4637 protected function execute (InputInterface $ input , OutputInterface $ output ): int
4738 {
4839 $ io = new SymfonyStyle ($ input , $ output );
@@ -99,18 +90,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9990 ]
10091 );
10192
102- // Display PHP extensions in a separate table
10393 if (!empty ($ phpExtensions )) {
10494 $ io ->section ('PHP Extensions ' );
105- $ io ->table (['Extension ' , 'Status ' ], $ phpExtensions );
95+ $ io ->table (['Component ' , 'Version/ Status ' ], $ phpExtensions );
10696 }
10797
10898 return Cli::RETURN_SUCCESS ;
10999 }
110100
111- /**
112- * Get the latest LTS Node.js version from the Node.js API
113- */
114101 private function getLatestLtsNodeVersion (): string
115102 {
116103 try {
@@ -137,25 +124,18 @@ private function getLatestLtsNodeVersion(): string
137124 }
138125 }
139126
140- /**
141- * Get a shortened MySQL version string
142- */
143127 private function getShortMysqlVersion (): string
144128 {
145129 return $ this ->extractVersionFromCommand ('mysql -V ' ) ??
146130 $ this ->extractVersionFromCommand ('mysqld --version ' ) ??
147131 'Unknown ' ;
148132 }
149133
150- /**
151- * Extract version number from command output using different patterns
152- */
153134 private function extractVersionFromCommand (string $ command ): ?string
154135 {
155136 try {
156137 $ output = $ this ->runCommand ($ command );
157138
158- // List of patterns to try, in order of preference
159139 $ patterns = [
160140 '/mysql Ver\s+(\d+\.\d+\.\d+)/ ' , // Standard MySQL Format
161141 '/Distrib\s+(\d+\.\d+\.\d+)/ ' , // Alternative format with Distrib
@@ -169,25 +149,19 @@ private function extractVersionFromCommand(string $command): ?string
169149 }
170150 }
171151
172- return $ output ; // Return the full output if no pattern matches
152+ return $ output ;
173153 } catch (\Exception $ e ) {
174154 return null ;
175155 }
176156 }
177157
178- /**
179- * Get database type (MySQL or MariaDB)
180- */
181158 private function getDatabaseType (): string
182159 {
183160 return $ this ->detectDatabaseTypeFromCommand ('mysql -V ' ) ??
184161 $ this ->detectDatabaseTypeFromCommand ('mysqld --version ' ) ??
185162 'Unknown ' ;
186163 }
187164
188- /**
189- * Detect database type from command output
190- */
191165 private function detectDatabaseTypeFromCommand (string $ command ): ?string
192166 {
193167 try {
@@ -207,28 +181,18 @@ private function detectDatabaseTypeFromCommand(string $command): ?string
207181 }
208182 }
209183
210- /**
211- * Get a shortened OS information string
212- */
213184 private function getShortOsInfo (): string
214185 {
215186 list ($ osName , , $ osVersion ) = explode (' ' , php_uname ());
216187 return ($ osName ?? 'Unknown ' ) . ' ' . ($ osVersion ?? 'Unknown ' );
217188 }
218189
219- /**
220- * Get the Node.js version
221- */
222190 private function getNodeVersion (): string
223191 {
224192 return $ this ->runCommand ('node -v ' );
225193 }
226194
227195 /**
228- * Run a command and return the output
229- *
230- * @param string $command
231- * @return string
232196 * @throws ProcessFailedException
233197 */
234198 private function runCommand (string $ command ): string
@@ -239,65 +203,47 @@ private function runCommand(string $command): string
239203 if (!$ process ->isSuccessful ()) {
240204 $ errorOutput = $ this ->escaper ->escapeHtml ($ process ->getErrorOutput ());
241205 $ output = $ this ->escaper ->escapeHtml ($ process ->getOutput ());
242- $ process ->setErrorOutput ($ errorOutput );
243- $ process ->setOutput ($ output );
244- throw new ProcessFailedException ($ process );
206+
207+ $ safeProcess = new Process (explode (' ' , $ command ));
208+ $ safeProcess ->setOutput ($ output );
209+ $ safeProcess ->setErrorOutput ($ errorOutput );
210+
211+ throw new ProcessFailedException ($ safeProcess );
245212 }
246213
247214 return $ this ->escaper ->escapeHtml (trim ($ process ->getOutput ()));
248215 }
249216
250- /**
251- * Get the Composer version
252- */
253217 private function getComposerVersion (): string
254218 {
255219 return $ this ->runCommand ('composer -V ' );
256220 }
257221
258- /**
259- * Get the NPM version
260- */
261222 private function getNpmVersion (): string
262223 {
263224 return $ this ->runCommand ('npm -v ' );
264225 }
265226
266- /**
267- * Get the Git version
268- */
269227 private function getGitVersion (): string
270228 {
271229 return $ this ->runCommand ('git --version ' );
272230 }
273231
274- /**
275- * Get the Xdebug status
276- */
277232 private function getXdebugStatus (): string
278233 {
279234 return extension_loaded ('xdebug ' ) ? 'Enabled ' : 'Disabled ' ;
280235 }
281236
282- /**
283- * Get the Redis status
284- */
285237 private function getRedisStatus (): string
286238 {
287239 return extension_loaded ('redis ' ) ? 'Enabled ' : 'Disabled ' ;
288240 }
289241
290- /**
291- * Get the search engine status
292- */
293242 private function getSearchEngineStatus (): string
294243 {
295244 return extension_loaded ('elasticsearch ' ) ? 'Enabled ' : 'Disabled ' ;
296245 }
297246
298- /**
299- * Get important PHP extensions
300- */
301247 private function getImportantPhpExtensions (): array
302248 {
303249 $ extensions = [
@@ -320,17 +266,11 @@ private function getImportantPhpExtensions(): array
320266 return $ result ;
321267 }
322268
323- /**
324- * Get the PHP memory limit
325- */
326269 private function getPhpMemoryLimit (): string
327270 {
328271 return ini_get ('memory_limit ' );
329272 }
330273
331- /**
332- * Get the disk space
333- */
334274 private function getDiskSpace (): string
335275 {
336276 $ freeSpace = disk_free_space ('/ ' );
@@ -343,9 +283,6 @@ private function getDiskSpace(): string
343283 );
344284 }
345285
346- /**
347- * Format bytes to a human-readable format
348- */
349286 private function formatBytes (float $ bytes ): string
350287 {
351288 $ units = ['B ' , 'KB ' , 'MB ' , 'GB ' , 'TB ' ];
0 commit comments