Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 43 additions & 20 deletions src/Console/Command/System/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Framework\Console\Cli;
use Magento\Framework\Escaper;
use Magento\Framework\HTTP\ClientFactory;
use Magento\Framework\Shell;
use OpenForgeProject\MageForge\Console\Command\AbstractCommand;
use Symfony\Component\Console\Helper\TableSeparator;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -25,12 +26,16 @@ class CheckCommand extends AbstractCommand
/**
* @param ProductMetadataInterface $productMetadata
* @param Escaper $escaper
* @param ResourceConnection $resourceConnection
* @param ClientFactory $httpClientFactory
* @param Shell $shell
*/
public function __construct(
private readonly ProductMetadataInterface $productMetadata,
private readonly Escaper $escaper,
private readonly ResourceConnection $resourceConnection,
private readonly ClientFactory $httpClientFactory
private readonly ClientFactory $httpClientFactory,
private readonly Shell $shell
) {
parent::__construct();
}
Expand Down Expand Up @@ -118,9 +123,13 @@ protected function executeCommand(InputInterface $input, OutputInterface $output
*/
private function getNodeVersion(): string
{
// phpcs:ignore Magento2.Security.InsecureFunction.Found -- exec required to check external tool version
exec('node -v 2>/dev/null', $output, $returnCode);
return $returnCode === 0 && !empty($output) ? trim($output[0], 'v') : 'Not installed';
try {
$output = trim($this->shell->execute('node -v 2>/dev/null'));
} catch (\Exception $e) {
return 'Not installed';
}

return $output !== '' ? ltrim($output, 'v') : 'Not installed';
}

/**
Expand Down Expand Up @@ -202,12 +211,14 @@ private function getMysqlVersionViaMagento(): ?string
*/
private function getMysqlVersionViaClient(): ?string
{
// phpcs:ignore Magento2.Security.InsecureFunction.Found -- exec required to check external tool version
exec('mysql --version 2>/dev/null', $output, $returnCode);
if ($returnCode === 0 && !empty($output)) {
$versionString = $output[0];
preg_match('/Distrib ([0-9.]+)/', $versionString, $matches);
try {
$output = trim($this->shell->execute('mysql --version 2>/dev/null'));
} catch (\Exception $e) {
return null;
}

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

Expand Down Expand Up @@ -301,13 +312,17 @@ private function getShortOsInfo(): string
*/
private function getComposerVersion(): string
{
// phpcs:ignore Magento2.Security.InsecureFunction.Found -- exec required to check external tool version
exec('composer --version 2>/dev/null', $output, $returnCode);
if ($returnCode !== 0 || empty($output)) {
try {
$output = trim($this->shell->execute('composer --version 2>/dev/null'));
} catch (\Exception $e) {
return 'Not installed';
}

if ($output === '') {
return 'Not installed';
}

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

Expand All @@ -318,9 +333,13 @@ private function getComposerVersion(): string
*/
private function getNpmVersion(): string
{
// phpcs:ignore Magento2.Security.InsecureFunction.Found -- exec required to check external tool version
exec('npm --version 2>/dev/null', $output, $returnCode);
return $returnCode === 0 && !empty($output) ? trim($output[0]) : 'Not installed';
try {
$output = trim($this->shell->execute('npm --version 2>/dev/null'));
} catch (\Exception $e) {
return 'Not installed';
}

return $output !== '' ? $output : 'Not installed';
}

/**
Expand All @@ -330,13 +349,17 @@ private function getNpmVersion(): string
*/
private function getGitVersion(): string
{
// phpcs:ignore Magento2.Security.InsecureFunction.Found -- exec required to check external tool version
exec('git --version 2>/dev/null', $output, $returnCode);
if ($returnCode !== 0 || empty($output)) {
try {
$output = trim($this->shell->execute('git --version 2>/dev/null'));
} catch (\Exception $e) {
return 'Not installed';
}

if ($output === '') {
return 'Not installed';
}

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

Expand Down
1 change: 0 additions & 1 deletion src/Service/Inspector/Cache/BlockCacheCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*
* Measures render time and extracts cache configuration with strict type safety (PHPStan Level 8).
*
* @package OpenForgeProject\MageForge
*/
class BlockCacheCollector
{
Expand Down
Loading