Skip to content

Commit 28123e6

Browse files
committed
fix: update phpstan level to 8 and improve commands
1 parent 31fb789 commit 28123e6

6 files changed

Lines changed: 32 additions & 10 deletions

File tree

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
parameters:
2-
level: 7
2+
level: 8
33
paths:
44
- src

src/Console/Command/Dev/InspectorCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace OpenForgeProject\MageForge\Console\Command\Dev;
66

77
use Magento\Framework\App\Cache\Manager as CacheManager;
8+
use Magento\Framework\App\Config\ScopeConfigInterface;
89
use Magento\Framework\App\Config\Storage\WriterInterface;
910
use Magento\Framework\App\State;
1011
use Magento\Framework\Console\Cli;
@@ -25,6 +26,7 @@ public function __construct(
2526
private readonly WriterInterface $configWriter,
2627
private readonly State $state,
2728
private readonly CacheManager $cacheManager,
29+
private readonly ScopeConfigInterface $scopeConfig,
2830
?string $name = null
2931
) {
3032
parent::__construct($name);
@@ -200,9 +202,7 @@ private function isDeveloperMode(): bool
200202
private function isInspectorEnabled(): bool
201203
{
202204
try {
203-
$scopeConfig = \Magento\Framework\App\ObjectManager::getInstance()
204-
->get(\Magento\Framework\App\Config\ScopeConfigInterface::class);
205-
return $scopeConfig->isSetFlag(self::XML_PATH_INSPECTOR_ENABLED);
205+
return $this->scopeConfig->isSetFlag(self::XML_PATH_INSPECTOR_ENABLED);
206206
} catch (\Exception $e) {
207207
return false;
208208
}

src/Console/Command/System/CheckCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
use Composer\Semver\Comparator;
88
use Magento\Framework\App\ProductMetadataInterface;
9+
use Magento\Framework\App\ResourceConnection;
910
use Magento\Framework\Console\Cli;
1011
use Magento\Framework\Escaper;
12+
use Magento\Framework\HTTP\ClientFactory;
1113
use OpenForgeProject\MageForge\Console\Command\AbstractCommand;
1214
use Symfony\Component\Console\Helper\TableSeparator;
1315
use Symfony\Component\Console\Input\InputInterface;
@@ -27,6 +29,8 @@ class CheckCommand extends AbstractCommand
2729
public function __construct(
2830
private readonly ProductMetadataInterface $productMetadata,
2931
private readonly Escaper $escaper,
32+
private readonly ResourceConnection $resourceConnection,
33+
private readonly ClientFactory $httpClientFactory
3034
) {
3135
parent::__construct();
3236
}
@@ -181,9 +185,7 @@ private function getShortMysqlVersion(): string
181185
private function getMysqlVersionViaMagento(): ?string
182186
{
183187
try {
184-
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
185-
$resource = $objectManager->get(\Magento\Framework\App\ResourceConnection::class);
186-
$connection = $resource->getConnection();
188+
$connection = $this->resourceConnection->getConnection();
187189
$version = $connection->fetchOne('SELECT VERSION()');
188190

189191
return !empty($version) ? $version : null;
@@ -584,9 +586,7 @@ private function testElasticsearchConnection(string $url)
584586
private function tryMagentoHttpClient(string $url): ?array
585587
{
586588
try {
587-
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
588-
$httpClientFactory = $objectManager->get(\Magento\Framework\HTTP\ClientFactory::class);
589-
$httpClient = $httpClientFactory->create();
589+
$httpClient = $this->httpClientFactory->create();
590590
$httpClient->setTimeout(2);
591591
$httpClient->get($url);
592592

src/Console/Command/Theme/BuildCommand.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ private function buildValidatedTheme(
262262
): bool {
263263
$themePath = $this->themePath->getPath($themeCode);
264264

265+
if ($themePath === null) {
266+
$io->error("Could not find path for theme $themeCode.");
267+
return false;
268+
}
269+
265270
// Find appropriate builder
266271
$builder = $this->builderPool->getBuilder($themePath);
267272
if ($builder === null) {
@@ -447,6 +452,9 @@ private function sanitizeNumericValue(string $value): ?string
447452
private function sanitizeTermValue(string $value): ?string
448453
{
449454
$sanitized = preg_replace('/[^a-zA-Z0-9\-]/', '', $value);
455+
if ($sanitized === null) {
456+
return null;
457+
}
450458
return (strlen($sanitized) > 0 && strlen($sanitized) <= 50) ? $sanitized : null;
451459
}
452460

@@ -465,6 +473,9 @@ private function sanitizeBooleanValue(string $value): ?string
465473
private function sanitizeAlphanumericValue(string $value): ?string
466474
{
467475
$sanitized = preg_replace('/[^\w\-.]/', '', $value);
476+
if ($sanitized === null) {
477+
return null;
478+
}
468479
return (strlen($sanitized) > 0 && strlen($sanitized) <= 255) ? $sanitized : null;
469480
}
470481

src/Console/Command/Theme/CleanCommand.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,9 @@ private function sanitizeNumericValue(string $value): ?string
599599
private function sanitizeTermValue(string $value): ?string
600600
{
601601
$sanitized = preg_replace('/[^a-zA-Z0-9\-]/', '', $value);
602+
if ($sanitized === null) {
603+
return null;
604+
}
602605
return (strlen($sanitized) > 0 && strlen($sanitized) <= 50) ? $sanitized : null;
603606
}
604607

@@ -617,6 +620,9 @@ private function sanitizeBooleanValue(string $value): ?string
617620
private function sanitizeAlphanumericValue(string $value): ?string
618621
{
619622
$sanitized = preg_replace('/[^\w\-.]/', '', $value);
623+
if ($sanitized === null) {
624+
return null;
625+
}
620626
return (strlen($sanitized) > 0 && strlen($sanitized) <= 255) ? $sanitized : null;
621627
}
622628

src/Console/Command/Theme/WatchCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ protected function executeCommand(InputInterface $input, OutputInterface $output
114114
}
115115

116116
$builder = $this->builderPool->getBuilder($themePath);
117+
if ($builder === null) {
118+
$this->io->error("No suitable builder found for theme $themeCode.");
119+
return self::FAILURE;
120+
}
121+
117122
return $builder->watch($themeCode, $themePath, $this->io, $output, $isVerbose) ? self::SUCCESS : self::FAILURE;
118123
}
119124
}

0 commit comments

Comments
 (0)