diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 31d59d8..9cbe22b 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -114,6 +114,5 @@ jobs: - name: Run PHPStan working-directory: magento2 - continue-on-error: true run: | vendor/bin/phpstan analyse -c vendor/openforgeproject/mageforge/phpstan.neon vendor/openforgeproject/mageforge/src diff --git a/phpstan.neon b/phpstan.neon index 6e451fa..91e6453 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,4 @@ parameters: - level: 6 + level: 5 paths: - src diff --git a/src/Console/Command/Dev/InspectorCommand.php b/src/Console/Command/Dev/InspectorCommand.php index a5ce56b..048d6e3 100644 --- a/src/Console/Command/Dev/InspectorCommand.php +++ b/src/Console/Command/Dev/InspectorCommand.php @@ -116,7 +116,6 @@ protected function executeCommand(InputInterface $input, OutputInterface $output 'enable' => $this->enableInspector(), 'disable' => $this->disableInspector(), 'status' => $this->showStatus(), - default => Cli::RETURN_FAILURE, }; } diff --git a/src/Console/Command/System/CheckCommand.php b/src/Console/Command/System/CheckCommand.php index ff69833..ae5dace 100644 --- a/src/Console/Command/System/CheckCommand.php +++ b/src/Console/Command/System/CheckCommand.php @@ -238,7 +238,7 @@ private function getMysqlVersionViaPdo(): ?string /** * Get database configuration from environment variables * - * @return array + * @return array */ private function getDatabaseConfig(): array { @@ -500,7 +500,7 @@ private function checkSearchEngineConnections(): ?string /** * Get potential search engine hosts * - * @return array + * @return string[] */ private function getSearchEngineHosts(): array { @@ -531,7 +531,7 @@ private function getSearchEngineHosts(): array /** * Format search engine version output * - * @param array $info + * @param array $info * @return string */ private function formatSearchEngineVersion(array $info): string @@ -549,7 +549,7 @@ private function formatSearchEngineVersion(array $info): string * Test Elasticsearch connection and return version info * * @param string $url - * @return array|bool + * @return array|false */ private function testElasticsearchConnection(string $url) { @@ -573,7 +573,7 @@ private function testElasticsearchConnection(string $url) * Try to connect using Magento's HTTP client * * @param string $url - * @return array|null + * @return array|null */ private function tryMagentoHttpClient(string $url): ?array { @@ -603,7 +603,7 @@ private function tryMagentoHttpClient(string $url): ?array /** * Get important PHP extensions * - * @return array + * @return array> */ private function getImportantPhpExtensions(): array { @@ -757,8 +757,8 @@ private function getSystemEnvironmentValue(string $name): ?string { // Use ini_get for certain system variables as a safer alternative if (in_array($name, ['memory_limit', 'max_execution_time'])) { - $value = ini_get($name); - if ($value !== false) { + $value = (string)ini_get($name); + if ($value !== '') { return $value; } } diff --git a/src/Console/Command/System/VersionCommand.php b/src/Console/Command/System/VersionCommand.php index d2e5ff6..64392af 100644 --- a/src/Console/Command/System/VersionCommand.php +++ b/src/Console/Command/System/VersionCommand.php @@ -17,7 +17,6 @@ class VersionCommand extends AbstractCommand { private const API_URL = 'https://api.github.com/repos/openforgeproject/mageforge/releases/latest'; - private const PACKAGE_NAME = 'openforgeproject/mageforge'; private const UNKNOWN_VERSION = 'Unknown'; /** diff --git a/src/Console/Command/Theme/BuildCommand.php b/src/Console/Command/Theme/BuildCommand.php index 793d5ba..1d807f3 100644 --- a/src/Console/Command/Theme/BuildCommand.php +++ b/src/Console/Command/Theme/BuildCommand.php @@ -492,7 +492,7 @@ private function getServerVar(string $name): ?string private function setEnvVar(string $name, string $value): void { // Validate input parameters - if (empty($name) || !is_string($name)) { + if (empty($name) ) { return; } diff --git a/src/Console/Command/Theme/CleanCommand.php b/src/Console/Command/Theme/CleanCommand.php index 2d223aa..1ed6e0e 100644 --- a/src/Console/Command/Theme/CleanCommand.php +++ b/src/Console/Command/Theme/CleanCommand.php @@ -638,7 +638,7 @@ private function getServerVar(string $name): ?string */ private function setEnvVar(string $name, string $value): void { - if (empty($name) || !is_string($name)) { + if (empty($name) ) { return; } diff --git a/src/Console/Command/Theme/TokensCommand.php b/src/Console/Command/Theme/TokensCommand.php index 9255b9c..5b1687c 100644 --- a/src/Console/Command/Theme/TokensCommand.php +++ b/src/Console/Command/Theme/TokensCommand.php @@ -125,7 +125,7 @@ private function validateHyvaTheme(string $themeCode, OutputInterface $output): // If no theme was selected, exit if ($correctedTheme === null) { - return Cli::RETURN_FAILURE; + return null; } // Use the corrected theme code @@ -135,7 +135,7 @@ private function validateHyvaTheme(string $themeCode, OutputInterface $output): // Double-check the corrected theme exists if ($themePath === null) { $this->io->error("Theme $themeCode is not installed."); - return Cli::RETURN_FAILURE; + return null; } $this->io->info("Using theme: $themeCode"); diff --git a/src/Model/TemplateEngine/Decorator/InspectorHints.php b/src/Model/TemplateEngine/Decorator/InspectorHints.php index 0e511fa..a544097 100644 --- a/src/Model/TemplateEngine/Decorator/InspectorHints.php +++ b/src/Model/TemplateEngine/Decorator/InspectorHints.php @@ -62,6 +62,10 @@ public function render(BlockInterface $block, $templateFile, array $dictionary = { $result = $this->subject->render($block, $templateFile, $dictionary); + if (!$this->showBlockHints) { + return $result; + } + // Only inject attributes if there's actual HTML content if (empty(trim($result))) { return $result; @@ -184,7 +188,7 @@ private function getParentBlockName(BlockInterface $block): string { if ($block instanceof AbstractBlock) { $parent = $block->getParentBlock(); - if ($parent && method_exists($parent, 'getNameInLayout')) { + if ($parent instanceof AbstractBlock) { return $parent->getNameInLayout() ?: ''; } } @@ -200,7 +204,7 @@ private function getParentBlockName(BlockInterface $block): string */ private function getBlockAlias(BlockInterface $block): string { - if ($block instanceof AbstractBlock && method_exists($block, 'getNameInLayout')) { + if ($block instanceof AbstractBlock) { return $block->getNameInLayout() ?: ''; } diff --git a/src/Model/TemplateEngine/Decorator/InspectorHintsFactory.php b/src/Model/TemplateEngine/Decorator/InspectorHintsFactory.php index 5360ad0..c5fe32b 100644 --- a/src/Model/TemplateEngine/Decorator/InspectorHintsFactory.php +++ b/src/Model/TemplateEngine/Decorator/InspectorHintsFactory.php @@ -5,30 +5,31 @@ namespace OpenForgeProject\MageForge\Model\TemplateEngine\Decorator; use Magento\Framework\ObjectManagerInterface; +use OpenForgeProject\MageForge\Model\TemplateEngine\Decorator\InspectorHints; /** * Factory for InspectorHints decorator */ class InspectorHintsFactory { - private ObjectManagerInterface $objectManager; - /** * @param ObjectManagerInterface $objectManager */ - public function __construct(ObjectManagerInterface $objectManager) - { - $this->objectManager = $objectManager; + public function __construct( + private readonly ObjectManagerInterface $objectManager + ) { } /** * Create InspectorHints instance * - * @param array $data + * @param array $data * @return InspectorHints */ public function create(array $data = []): InspectorHints { - return $this->objectManager->create(InspectorHints::class, $data); + /** @var InspectorHints $instance */ + $instance = $this->objectManager->create(InspectorHints::class, $data); + return $instance; } } diff --git a/src/Model/TemplateEngine/Plugin/InspectorHints.php b/src/Model/TemplateEngine/Plugin/InspectorHints.php index 31e74cc..84d92a1 100644 --- a/src/Model/TemplateEngine/Plugin/InspectorHints.php +++ b/src/Model/TemplateEngine/Plugin/InspectorHints.php @@ -59,7 +59,7 @@ public function __construct( * @param TemplateEngineFactory $subject * @param TemplateEngineInterface $invocationResult * @return TemplateEngineInterface - * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @SuppressWarnings("PHPMD.UnusedFormalParameter") */ public function afterCreate( TemplateEngineFactory $subject, diff --git a/src/Model/ThemePath.php b/src/Model/ThemePath.php index 37bff14..e4c739e 100644 --- a/src/Model/ThemePath.php +++ b/src/Model/ThemePath.php @@ -6,14 +6,11 @@ use Magento\Framework\Component\ComponentRegistrar; use Magento\Framework\Component\ComponentRegistrarInterface; -use Magento\Theme\Model\ResourceModel\Theme\Collection as ThemeCollection; class ThemePath { public function __construct( - private readonly ThemeList $themeList, - private readonly ComponentRegistrarInterface $componentRegistrar, - private readonly ThemeCollection $themeCollection + private readonly ComponentRegistrarInterface $componentRegistrar ) { } diff --git a/src/Service/Hyva/CompatibilityChecker.php b/src/Service/Hyva/CompatibilityChecker.php index 219475c..2cadd0f 100644 --- a/src/Service/Hyva/CompatibilityChecker.php +++ b/src/Service/Hyva/CompatibilityChecker.php @@ -19,8 +19,7 @@ class CompatibilityChecker { public function __construct( private readonly ComponentRegistrarInterface $componentRegistrar, - private readonly ModuleScanner $moduleScanner, - private readonly IncompatibilityDetector $incompatibilityDetector + private readonly ModuleScanner $moduleScanner ) { } diff --git a/src/Service/StaticContentCleaner.php b/src/Service/StaticContentCleaner.php index bd9cd82..311a261 100644 --- a/src/Service/StaticContentCleaner.php +++ b/src/Service/StaticContentCleaner.php @@ -61,7 +61,7 @@ public function cleanIfNeeded( $cleanedStatic = $this->themeCleaner->cleanPubStatic($themeCode, $io, false, $isVerbose); $cleanedPreprocessed = $this->themeCleaner->cleanViewPreprocessed($themeCode, $io, false, $isVerbose); - return ($cleanedStatic > 0 || $cleanedPreprocessed > 0) || !$this->themeCleaner->hasStaticFiles($themeCode); + return ($cleanedStatic > 0 || $cleanedPreprocessed > 0); } catch (\Exception $e) { $io->error('Failed to check/clean static content: ' . $e->getMessage()); return false;