Skip to content

Commit 625c6da

Browse files
authored
fix: phpcs errors (#138)
* fix: remove package annotation from BlockCacheCollector * fix: replace exec with shell execution for commands
1 parent 9c01ce5 commit 625c6da

2 files changed

Lines changed: 43 additions & 21 deletions

File tree

src/Console/Command/System/CheckCommand.php

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\Console\Cli;
1111
use Magento\Framework\Escaper;
1212
use Magento\Framework\HTTP\ClientFactory;
13+
use Magento\Framework\Shell;
1314
use OpenForgeProject\MageForge\Console\Command\AbstractCommand;
1415
use Symfony\Component\Console\Helper\TableSeparator;
1516
use Symfony\Component\Console\Input\InputInterface;
@@ -25,12 +26,16 @@ class CheckCommand extends AbstractCommand
2526
/**
2627
* @param ProductMetadataInterface $productMetadata
2728
* @param Escaper $escaper
29+
* @param ResourceConnection $resourceConnection
30+
* @param ClientFactory $httpClientFactory
31+
* @param Shell $shell
2832
*/
2933
public function __construct(
3034
private readonly ProductMetadataInterface $productMetadata,
3135
private readonly Escaper $escaper,
3236
private readonly ResourceConnection $resourceConnection,
33-
private readonly ClientFactory $httpClientFactory
37+
private readonly ClientFactory $httpClientFactory,
38+
private readonly Shell $shell
3439
) {
3540
parent::__construct();
3641
}
@@ -118,9 +123,13 @@ protected function executeCommand(InputInterface $input, OutputInterface $output
118123
*/
119124
private function getNodeVersion(): string
120125
{
121-
// phpcs:ignore Magento2.Security.InsecureFunction.Found -- exec required to check external tool version
122-
exec('node -v 2>/dev/null', $output, $returnCode);
123-
return $returnCode === 0 && !empty($output) ? trim($output[0], 'v') : 'Not installed';
126+
try {
127+
$output = trim($this->shell->execute('node -v 2>/dev/null'));
128+
} catch (\Exception $e) {
129+
return 'Not installed';
130+
}
131+
132+
return $output !== '' ? ltrim($output, 'v') : 'Not installed';
124133
}
125134

126135
/**
@@ -202,12 +211,14 @@ private function getMysqlVersionViaMagento(): ?string
202211
*/
203212
private function getMysqlVersionViaClient(): ?string
204213
{
205-
// phpcs:ignore Magento2.Security.InsecureFunction.Found -- exec required to check external tool version
206-
exec('mysql --version 2>/dev/null', $output, $returnCode);
207-
if ($returnCode === 0 && !empty($output)) {
208-
$versionString = $output[0];
209-
preg_match('/Distrib ([0-9.]+)/', $versionString, $matches);
214+
try {
215+
$output = trim($this->shell->execute('mysql --version 2>/dev/null'));
216+
} catch (\Exception $e) {
217+
return null;
218+
}
210219

220+
if ($output !== '') {
221+
preg_match('/Distrib ([0-9.]+)/', $output, $matches);
211222
return isset($matches[1]) ? $matches[1] : null;
212223
}
213224

@@ -301,13 +312,17 @@ private function getShortOsInfo(): string
301312
*/
302313
private function getComposerVersion(): string
303314
{
304-
// phpcs:ignore Magento2.Security.InsecureFunction.Found -- exec required to check external tool version
305-
exec('composer --version 2>/dev/null', $output, $returnCode);
306-
if ($returnCode !== 0 || empty($output)) {
315+
try {
316+
$output = trim($this->shell->execute('composer --version 2>/dev/null'));
317+
} catch (\Exception $e) {
318+
return 'Not installed';
319+
}
320+
321+
if ($output === '') {
307322
return 'Not installed';
308323
}
309324

310-
preg_match('/Composer version ([^ ]+)/', $output[0], $matches);
325+
preg_match('/Composer version ([^ ]+)/', $output, $matches);
311326
return isset($matches[1]) ? $matches[1] : 'Unknown';
312327
}
313328

@@ -318,9 +333,13 @@ private function getComposerVersion(): string
318333
*/
319334
private function getNpmVersion(): string
320335
{
321-
// phpcs:ignore Magento2.Security.InsecureFunction.Found -- exec required to check external tool version
322-
exec('npm --version 2>/dev/null', $output, $returnCode);
323-
return $returnCode === 0 && !empty($output) ? trim($output[0]) : 'Not installed';
336+
try {
337+
$output = trim($this->shell->execute('npm --version 2>/dev/null'));
338+
} catch (\Exception $e) {
339+
return 'Not installed';
340+
}
341+
342+
return $output !== '' ? $output : 'Not installed';
324343
}
325344

326345
/**
@@ -330,13 +349,17 @@ private function getNpmVersion(): string
330349
*/
331350
private function getGitVersion(): string
332351
{
333-
// phpcs:ignore Magento2.Security.InsecureFunction.Found -- exec required to check external tool version
334-
exec('git --version 2>/dev/null', $output, $returnCode);
335-
if ($returnCode !== 0 || empty($output)) {
352+
try {
353+
$output = trim($this->shell->execute('git --version 2>/dev/null'));
354+
} catch (\Exception $e) {
355+
return 'Not installed';
356+
}
357+
358+
if ($output === '') {
336359
return 'Not installed';
337360
}
338361

339-
preg_match('/git version (.+)/', $output[0], $matches);
362+
preg_match('/git version (.+)/', $output, $matches);
340363
return isset($matches[1]) ? $matches[1] : 'Unknown';
341364
}
342365

src/Service/Inspector/Cache/BlockCacheCollector.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*
1313
* Measures render time and extracts cache configuration with strict type safety (PHPStan Level 8).
1414
*
15-
* @package OpenForgeProject\MageForge
1615
*/
1716
class BlockCacheCollector
1817
{

0 commit comments

Comments
 (0)