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, including default value type resolution (new in 2.2.1). For example, rex_addon::get('yforms', ['default' => new rex_yforms_addon()]) will now correctly infer the resolved return type.
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. New in 2.2.1: Default values in method calls (e.g., rex_sql::factory(['table' => 'rex_content', 'default' => []])) now resolve to their explicit types, reducing mixed inferences.
Analyze dynamic patterns confidently:
Use Psalm’s @psalm-return/@psalm-param alongside REDAXO conventions (e.g., rex_addon::get(), rex_fragment::show()). The plugin now propagates default value types through method chains, e.g.:
$addon = rex_addon::get('yforms', ['default' => new rex_yforms_addon()]);
// $addon is now correctly typed as rex_yforms_addon|rex_addon
Integrate with CI:
Add psalm --output-format=checkstyle > psalm-report.xml to your pipeline. The 2.2.1 fix reduces false positives for default-value-heavy code (e.g., rex_config::get('foo', ['default' => []])).
Extend type safety with custom stubs:
For private add-ons, use additionalFiles in psalm.xml to include stubs. The plugin now respects default value types in stubs, ensuring consistency with core behavior.
Stubs may lag behind REDAXO core updates:
Check the plugin’s src/Stub/ directory for compatibility (≥5.13+). If signatures (e.g., rex_sql methods) are outdated, override via <stubs> in psalm.xml. New in 2.2.1: Default value types in stubs now take precedence, so test overrides thoroughly.
rex_sql type inference nuances:
While the plugin handles rex_sql::factory(), chained methods like ->getValue('foo') may still infer mixed. Mitigate with:
/** @var string $foo */
$foo = $sql->getValue('foo');
Pro Tip: Enable _propertyReferences in psalm.xml for better default value resolution.
Avoid rex_addon::load() false negatives:
Psalm now correctly infers rex_yforms_addon for rex_addon::get('yforms') if default values are typed. Ensure packages/ is scanned in psalm.xml:
<directory name="packages"/>
<directory name="redaxo/src/addons"/>
Suppress only REDAXO-specific false positives:
Use @psalm-suppress sparingly. For default-value issues (e.g., rex_config::get()), verify the fix in 2.2.1 resolves it before suppressing:
/** @psalm-suppress InvalidArgument */
rex_config::get('foo', ['default' => ['bar']]); // Now correctly typed as array<string, mixed>
Check the plugin issue tracker for known edge cases.
How can I help you explore Laravel packages today?