diff --git a/phpstan.neon b/phpstan.neon index 1d5823a..1ff472c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,4 @@ parameters: - level: 7 + level: 8 paths: - src diff --git a/src/Console/Command/Dev/InspectorCommand.php b/src/Console/Command/Dev/InspectorCommand.php index a21cbb9..0fe9674 100644 --- a/src/Console/Command/Dev/InspectorCommand.php +++ b/src/Console/Command/Dev/InspectorCommand.php @@ -5,6 +5,7 @@ namespace OpenForgeProject\MageForge\Console\Command\Dev; use Magento\Framework\App\Cache\Manager as CacheManager; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Config\Storage\WriterInterface; use Magento\Framework\App\State; use Magento\Framework\Console\Cli; @@ -25,6 +26,7 @@ public function __construct( private readonly WriterInterface $configWriter, private readonly State $state, private readonly CacheManager $cacheManager, + private readonly ScopeConfigInterface $scopeConfig, ?string $name = null ) { parent::__construct($name); @@ -200,9 +202,7 @@ private function isDeveloperMode(): bool private function isInspectorEnabled(): bool { try { - $scopeConfig = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\App\Config\ScopeConfigInterface::class); - return $scopeConfig->isSetFlag(self::XML_PATH_INSPECTOR_ENABLED); + return $this->scopeConfig->isSetFlag(self::XML_PATH_INSPECTOR_ENABLED); } catch (\Exception $e) { return false; } diff --git a/src/Console/Command/System/CheckCommand.php b/src/Console/Command/System/CheckCommand.php index 52f6a75..110568c 100644 --- a/src/Console/Command/System/CheckCommand.php +++ b/src/Console/Command/System/CheckCommand.php @@ -6,8 +6,10 @@ use Composer\Semver\Comparator; use Magento\Framework\App\ProductMetadataInterface; +use Magento\Framework\App\ResourceConnection; use Magento\Framework\Console\Cli; use Magento\Framework\Escaper; +use Magento\Framework\HTTP\ClientFactory; use OpenForgeProject\MageForge\Console\Command\AbstractCommand; use Symfony\Component\Console\Helper\TableSeparator; use Symfony\Component\Console\Input\InputInterface; @@ -27,6 +29,8 @@ class CheckCommand extends AbstractCommand public function __construct( private readonly ProductMetadataInterface $productMetadata, private readonly Escaper $escaper, + private readonly ResourceConnection $resourceConnection, + private readonly ClientFactory $httpClientFactory ) { parent::__construct(); } @@ -181,9 +185,7 @@ private function getShortMysqlVersion(): string private function getMysqlVersionViaMagento(): ?string { try { - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); - $resource = $objectManager->get(\Magento\Framework\App\ResourceConnection::class); - $connection = $resource->getConnection(); + $connection = $this->resourceConnection->getConnection(); $version = $connection->fetchOne('SELECT VERSION()'); return !empty($version) ? $version : null; @@ -584,9 +586,7 @@ private function testElasticsearchConnection(string $url) private function tryMagentoHttpClient(string $url): ?array { try { - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); - $httpClientFactory = $objectManager->get(\Magento\Framework\HTTP\ClientFactory::class); - $httpClient = $httpClientFactory->create(); + $httpClient = $this->httpClientFactory->create(); $httpClient->setTimeout(2); $httpClient->get($url); diff --git a/src/Console/Command/Theme/BuildCommand.php b/src/Console/Command/Theme/BuildCommand.php index 0b2fbef..4d43720 100644 --- a/src/Console/Command/Theme/BuildCommand.php +++ b/src/Console/Command/Theme/BuildCommand.php @@ -262,6 +262,11 @@ private function buildValidatedTheme( ): bool { $themePath = $this->themePath->getPath($themeCode); + if ($themePath === null) { + $io->error("Could not find path for theme $themeCode."); + return false; + } + // Find appropriate builder $builder = $this->builderPool->getBuilder($themePath); if ($builder === null) { @@ -447,6 +452,9 @@ private function sanitizeNumericValue(string $value): ?string private function sanitizeTermValue(string $value): ?string { $sanitized = preg_replace('/[^a-zA-Z0-9\-]/', '', $value); + if ($sanitized === null) { + return null; + } return (strlen($sanitized) > 0 && strlen($sanitized) <= 50) ? $sanitized : null; } @@ -465,6 +473,9 @@ private function sanitizeBooleanValue(string $value): ?string private function sanitizeAlphanumericValue(string $value): ?string { $sanitized = preg_replace('/[^\w\-.]/', '', $value); + if ($sanitized === null) { + return null; + } return (strlen($sanitized) > 0 && strlen($sanitized) <= 255) ? $sanitized : null; } diff --git a/src/Console/Command/Theme/CleanCommand.php b/src/Console/Command/Theme/CleanCommand.php index d7fe658..995ad53 100644 --- a/src/Console/Command/Theme/CleanCommand.php +++ b/src/Console/Command/Theme/CleanCommand.php @@ -599,6 +599,9 @@ private function sanitizeNumericValue(string $value): ?string private function sanitizeTermValue(string $value): ?string { $sanitized = preg_replace('/[^a-zA-Z0-9\-]/', '', $value); + if ($sanitized === null) { + return null; + } return (strlen($sanitized) > 0 && strlen($sanitized) <= 50) ? $sanitized : null; } @@ -617,6 +620,9 @@ private function sanitizeBooleanValue(string $value): ?string private function sanitizeAlphanumericValue(string $value): ?string { $sanitized = preg_replace('/[^\w\-.]/', '', $value); + if ($sanitized === null) { + return null; + } return (strlen($sanitized) > 0 && strlen($sanitized) <= 255) ? $sanitized : null; } diff --git a/src/Console/Command/Theme/WatchCommand.php b/src/Console/Command/Theme/WatchCommand.php index 03c3738..91d1800 100644 --- a/src/Console/Command/Theme/WatchCommand.php +++ b/src/Console/Command/Theme/WatchCommand.php @@ -114,6 +114,11 @@ protected function executeCommand(InputInterface $input, OutputInterface $output } $builder = $this->builderPool->getBuilder($themePath); + if ($builder === null) { + $this->io->error("No suitable builder found for theme $themeCode."); + return self::FAILURE; + } + return $builder->watch($themeCode, $themePath, $this->io, $output, $isVerbose) ? self::SUCCESS : self::FAILURE; } }