Skip to content

Commit 7c84ae7

Browse files
authored
fix: update phpstan level to 7 and improve error handling (#118)
1 parent 0a4a5fa commit 7c84ae7

7 files changed

Lines changed: 39 additions & 4 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: 6
2+
level: 7
33
paths:
44
- src

src/Console/Command/System/CheckCommand.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ protected function executeCommand(InputInterface $input, OutputInterface $output
5252
$dbType = $this->getDatabaseType();
5353
$osInfo = $this->getShortOsInfo();
5454
$magentoVersion = $this->productMetadata->getVersion();
55+
/** @var string $latestLtsNodeVersion */
5556
$latestLtsNodeVersion = $this->escaper->escapeHtml($this->getLatestLtsNodeVersion());
5657
$composerVersion = $this->getComposerVersion();
5758
$npmVersion = $this->getNpmVersion();
@@ -227,9 +228,14 @@ private function getMysqlVersionViaPdo(): ?string
227228

228229
$dsn = "mysql:host=$host;port=$port";
229230
$pdo = new \PDO($dsn, $user, $pass, [\PDO::ATTR_TIMEOUT => 1]);
230-
$version = $pdo->query('SELECT VERSION()')->fetchColumn();
231+
$stmt = $pdo->query('SELECT VERSION()');
232+
if ($stmt === false) {
233+
return null;
234+
}
231235

232-
return !empty($version) ? $version : null;
236+
$version = $stmt->fetchColumn();
237+
238+
return !empty($version) ? (string)$version : null;
233239
} catch (\Exception $e) {
234240
return null;
235241
}

src/Console/Command/Theme/TokensCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ private function generateTokens(string $tailwindPath, string $themeCode, bool $i
175175
}
176176

177177
$currentDir = getcwd();
178+
if ($currentDir === false) {
179+
$this->io->error("Cannot determine current directory");
180+
return false;
181+
}
178182
chdir($tailwindPath);
179183

180184
try {

src/Model/TemplateEngine/Decorator/InspectorHints.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ private function injectInspectorAttributes(string $html, BlockInterface $block,
105105
// JSON encode with proper escaping for HTML comments
106106
$jsonMetadata = json_encode($metadata, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
107107

108+
if ($jsonMetadata === false) {
109+
return $html;
110+
}
111+
108112
// Escape any comment terminators in JSON to prevent breaking out of comment
109113
$jsonMetadata = str_replace('-->', '-->', $jsonMetadata);
110114

@@ -164,7 +168,7 @@ private function getViewModel(BlockInterface $block): string
164168
{
165169
if (method_exists($block, 'getViewModel')) {
166170
$viewModel = $block->getViewModel();
167-
if ($viewModel) {
171+
if (is_object($viewModel)) {
168172
return get_class($viewModel);
169173
}
170174
}

src/Service/NodePackageManager.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public function __construct(
3131
public function installNodeModules(string $path, SymfonyStyle $io, bool $isVerbose): bool
3232
{
3333
$currentDir = getcwd();
34+
if ($currentDir === false) {
35+
$io->error('Cannot determine current directory');
36+
return false;
37+
}
38+
3439
chdir($path);
3540

3641
try {
@@ -85,6 +90,10 @@ public function isNodeModulesInSync(string $path): bool
8590
}
8691

8792
$currentDir = getcwd();
93+
if ($currentDir === false) {
94+
return false;
95+
}
96+
8897
chdir($path);
8998

9099
try {
@@ -107,6 +116,10 @@ public function isNodeModulesInSync(string $path): bool
107116
public function checkOutdatedPackages(string $path, SymfonyStyle $io): void
108117
{
109118
$currentDir = getcwd();
119+
if ($currentDir === false) {
120+
return;
121+
}
122+
110123
chdir($path);
111124

112125
try {

src/Service/ThemeBuilder/HyvaThemes/Builder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ private function buildTheme(string $themePath, SymfonyStyle $io, bool $isVerbose
130130

131131
// Change to tailwind directory and run build
132132
$currentDir = getcwd();
133+
if ($currentDir === false) {
134+
$io->error('Cannot determine current directory');
135+
return false;
136+
}
133137
chdir($tailwindPath);
134138

135139
try {

src/Service/ThemeBuilder/TailwindCSS/Builder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ public function build(string $themeCode, string $themePath, SymfonyStyle $io, Ou
8989

9090
// Change to tailwind directory and run build
9191
$currentDir = getcwd();
92+
if ($currentDir === false) {
93+
$io->error('Cannot determine current directory');
94+
return false;
95+
}
9296
chdir($tailwindPath);
9397

9498
try {

0 commit comments

Comments
 (0)