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
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
parameters:
level: 7
level: 8
paths:
- src
6 changes: 3 additions & 3 deletions src/Console/Command/Dev/InspectorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Console/Command/System/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions src/Console/Command/Theme/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions src/Console/Command/Theme/CleanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions src/Console/Command/Theme/WatchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Loading