diff --git a/phpstan.neon b/phpstan.neon index 6e451fa..1d5823a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,4 @@ parameters: - level: 6 + level: 7 paths: - src diff --git a/src/Console/Command/System/CheckCommand.php b/src/Console/Command/System/CheckCommand.php index ae5dace..52f6a75 100644 --- a/src/Console/Command/System/CheckCommand.php +++ b/src/Console/Command/System/CheckCommand.php @@ -52,6 +52,7 @@ protected function executeCommand(InputInterface $input, OutputInterface $output $dbType = $this->getDatabaseType(); $osInfo = $this->getShortOsInfo(); $magentoVersion = $this->productMetadata->getVersion(); + /** @var string $latestLtsNodeVersion */ $latestLtsNodeVersion = $this->escaper->escapeHtml($this->getLatestLtsNodeVersion()); $composerVersion = $this->getComposerVersion(); $npmVersion = $this->getNpmVersion(); @@ -227,9 +228,14 @@ private function getMysqlVersionViaPdo(): ?string $dsn = "mysql:host=$host;port=$port"; $pdo = new \PDO($dsn, $user, $pass, [\PDO::ATTR_TIMEOUT => 1]); - $version = $pdo->query('SELECT VERSION()')->fetchColumn(); + $stmt = $pdo->query('SELECT VERSION()'); + if ($stmt === false) { + return null; + } - return !empty($version) ? $version : null; + $version = $stmt->fetchColumn(); + + return !empty($version) ? (string)$version : null; } catch (\Exception $e) { return null; } diff --git a/src/Console/Command/Theme/TokensCommand.php b/src/Console/Command/Theme/TokensCommand.php index 5b1687c..f6daf36 100644 --- a/src/Console/Command/Theme/TokensCommand.php +++ b/src/Console/Command/Theme/TokensCommand.php @@ -175,6 +175,10 @@ private function generateTokens(string $tailwindPath, string $themeCode, bool $i } $currentDir = getcwd(); + if ($currentDir === false) { + $this->io->error("Cannot determine current directory"); + return false; + } chdir($tailwindPath); try { diff --git a/src/Model/TemplateEngine/Decorator/InspectorHints.php b/src/Model/TemplateEngine/Decorator/InspectorHints.php index fa4aa83..58cb927 100644 --- a/src/Model/TemplateEngine/Decorator/InspectorHints.php +++ b/src/Model/TemplateEngine/Decorator/InspectorHints.php @@ -105,6 +105,10 @@ private function injectInspectorAttributes(string $html, BlockInterface $block, // JSON encode with proper escaping for HTML comments $jsonMetadata = json_encode($metadata, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + if ($jsonMetadata === false) { + return $html; + } + // Escape any comment terminators in JSON to prevent breaking out of comment $jsonMetadata = str_replace('-->', '-->', $jsonMetadata); @@ -164,7 +168,7 @@ private function getViewModel(BlockInterface $block): string { if (method_exists($block, 'getViewModel')) { $viewModel = $block->getViewModel(); - if ($viewModel) { + if (is_object($viewModel)) { return get_class($viewModel); } } diff --git a/src/Service/NodePackageManager.php b/src/Service/NodePackageManager.php index 8966c70..8bd4fe6 100644 --- a/src/Service/NodePackageManager.php +++ b/src/Service/NodePackageManager.php @@ -31,6 +31,11 @@ public function __construct( public function installNodeModules(string $path, SymfonyStyle $io, bool $isVerbose): bool { $currentDir = getcwd(); + if ($currentDir === false) { + $io->error('Cannot determine current directory'); + return false; + } + chdir($path); try { @@ -85,6 +90,10 @@ public function isNodeModulesInSync(string $path): bool } $currentDir = getcwd(); + if ($currentDir === false) { + return false; + } + chdir($path); try { @@ -107,6 +116,10 @@ public function isNodeModulesInSync(string $path): bool public function checkOutdatedPackages(string $path, SymfonyStyle $io): void { $currentDir = getcwd(); + if ($currentDir === false) { + return; + } + chdir($path); try { diff --git a/src/Service/ThemeBuilder/HyvaThemes/Builder.php b/src/Service/ThemeBuilder/HyvaThemes/Builder.php index d02e2a5..6aed047 100644 --- a/src/Service/ThemeBuilder/HyvaThemes/Builder.php +++ b/src/Service/ThemeBuilder/HyvaThemes/Builder.php @@ -130,6 +130,10 @@ private function buildTheme(string $themePath, SymfonyStyle $io, bool $isVerbose // Change to tailwind directory and run build $currentDir = getcwd(); + if ($currentDir === false) { + $io->error('Cannot determine current directory'); + return false; + } chdir($tailwindPath); try { diff --git a/src/Service/ThemeBuilder/TailwindCSS/Builder.php b/src/Service/ThemeBuilder/TailwindCSS/Builder.php index 23e4ce4..766d2a4 100644 --- a/src/Service/ThemeBuilder/TailwindCSS/Builder.php +++ b/src/Service/ThemeBuilder/TailwindCSS/Builder.php @@ -89,6 +89,10 @@ public function build(string $themeCode, string $themePath, SymfonyStyle $io, Ou // Change to tailwind directory and run build $currentDir = getcwd(); + if ($currentDir === false) { + $io->error('Cannot determine current directory'); + return false; + } chdir($tailwindPath); try {