Skip to content

Commit a260693

Browse files
committed
✨ feat: add PHP_CodeSniffer configuration and improve exception messages
1 parent 286ae80 commit a260693

5 files changed

Lines changed: 28 additions & 6 deletions

File tree

phpcs.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="MageForge">
3+
<description>MageForge PHP_CodeSniffer Configuration</description>
4+
5+
<!-- Scan all PHP files in src directory -->
6+
<file>src</file>
7+
8+
<!-- Exclude vendor and generated directories -->
9+
<exclude-pattern>*/vendor/*</exclude-pattern>
10+
<exclude-pattern>*/generated/*</exclude-pattern>
11+
12+
<!-- Use PSR-12 as base standard -->
13+
<rule ref="PSR12"/>
14+
15+
<!-- Disable WordPress-specific rules (this is a Magento project) -->
16+
<rule ref="WordPress.Security.EscapeOutput">
17+
<severity>0</severity>
18+
</rule>
19+
20+
<!-- Show progress -->
21+
<arg name="colors"/>
22+
<arg value="sp"/>
23+
</ruleset>

src/Service/HyvaTokens/ConfigReader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function getConfig(string $themePath): array
4545
try {
4646
$jsonConfig = json_decode($configContent, true, 512, JSON_THROW_ON_ERROR);
4747
} catch (\JsonException $e) {
48-
throw new \Exception("Invalid JSON in configuration file: " . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8'));
48+
throw new \Exception("Invalid JSON in configuration file: " . $e->getMessage());
4949
}
5050

5151
if (isset($jsonConfig['tokens'])) {

src/Service/HyvaTokens/CssGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function write(string $content, string $outputPath): bool
6060
$this->fileDriver->filePutContents($outputPath, $content);
6161
return true;
6262
} catch (\Exception $e) {
63-
throw new \Exception("Failed to write CSS file: " . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8'));
63+
throw new \Exception("Failed to write CSS file: " . $e->getMessage());
6464
}
6565
}
6666
}

src/Service/HyvaTokens/TokenParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ public function parse(?string $filePath, ?array $inlineValues, string $format):
3434

3535
// Otherwise, read from file
3636
if ($filePath === null || !$this->fileDriver->isFile($filePath)) {
37-
throw new \Exception("Token source file not found: " . htmlspecialchars($filePath ?? 'null', ENT_QUOTES, 'UTF-8'));
37+
throw new \Exception("Token source file not found: " . ($filePath ?? 'null'));
3838
}
3939

4040
$content = $this->fileDriver->fileGetContents($filePath);
4141

4242
try {
4343
$tokens = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
4444
} catch (\JsonException $e) {
45-
throw new \Exception("Invalid JSON in token file: " . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8'));
45+
throw new \Exception("Invalid JSON in token file: " . $e->getMessage());
4646
}
4747

4848
return $this->normalizeTokens($tokens, $format);

src/Service/ThemeBuilder/BuilderFactory.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public function addBuilder(BuilderInterface $builder): void
1616
public function create(string $type): BuilderInterface
1717
{
1818
if (!isset($this->builders[$type])) {
19-
// phpcs:ignore WordPress.Security.EscapeOutput -- Exception message is properly escaped with htmlspecialchars
20-
throw new \InvalidArgumentException("Builder " . htmlspecialchars($type, ENT_QUOTES, 'UTF-8') . " not found");
19+
throw new \InvalidArgumentException("Builder $type not found");
2120
}
2221

2322
return $this->builders[$type];

0 commit comments

Comments
 (0)