redaxo/psalm-plugin
Psalm plugin for REDAXO projects providing improved static analysis through framework-specific stubs and type information. Helps Psalm understand REDAXO APIs, reduces false positives, and catches issues earlier in CI and local development.
Install the plugin via Composer in your REDAXO project:
composer require --dev redaxo/psalm-plugin
(Assumes Psalm is already installed; if not, run composer require --dev vimeo/psalm first.)
Enable the plugin in your psalm.xml:
<pluginClass class="Redaxo\PsalmPlugin\Plugin"/>
No additional config is required—the plugin auto-discovers REDAXO’s structure (e.g., redaxo/src, packages/).
Run your first analysis:
./vendor/bin/psalm
Expect immediate improvements in type accuracy for REDAXO-specific patterns like rex_backend_login, dynamic rex_package usage, or rex_sql query inference.
Leverage framework-aware stubs without manual overrides:
The plugin injects precise signatures for core classes (rex_backend_login, rex_logger, rex_file, etc.) and add-on APIs (e.g., rex_yrewrite or ystab), so Psalm infers correct return types (e.g., rex_clang objects, arrays of rex_category, etc.).
Analyze dynamic patterns confidently:
Use Psalm’s @psalm-return/@psalm-param annotations alongside REDAXO conventions (e.g., rex_addon::get(), rex_fragment::show()), and the plugin ensures Psalm understands return types even when values are derived from rex_context or rex_request.
Integrate with CI:
Add psalm --output-format=checkstyle > psalm-report.xml to your pipeline; the reduced false positives mean CI reports focus on real issues. For add-on development, set <projectFiles> to scan only /src or /packages/your_package/src.
Extend type safety with custom stubs:
If you maintain a private add-on with complex APIs, use additionalFiles in psalm.xml to include custom stubs—e.g., for custom rex_sql extensions—and the plugin will honor them.
Stubs may lag behind REDAXO core updates:
Check the plugin’s src/Stub/ directory for compatibility with your REDAXO version (≥5.13+). If you spot outdated signatures (e.g., missing rex_clang::getAll() return types), contribute stubs upstream or use <stubs> in psalm.xml as a temporary override.
rex_sql type inference nuances:
While the plugin handles basic rex_sql::factory() → rex_sql, chained methods like ->getValue('foo') may still infer mixed in complex joins. Mitigate by:
/** @var string $foo */
$foo = $sql->getValue('foo');
or enabling _propertyReferences analysis in psalm.xml.
Avoid rex_addon::load() false negatives:
When using rex_addon::get('yforms'), Psalm now correctly infers rex_yforms_addon (if installed), but only if packages/ is scanned. Ensure psalm.xml includes:
<directory name="packages"/>
<directory name="redaxo/src/addons"/>
Suppress only REDAXO-specific false positives:
Use @psalm-suppress sparingly. For example, if rex_logger::log()’s mixed $message type bugs you, write:
/** @psalm-suppress InvalidArgument */
rex_logger::log('error', ['context' => $e]);
...but first verify it’s not a plugin bug (check the plugin’s issue tracker).
How can I help you explore Laravel packages today?