savinmikhail/symfony-translatable-exceptions

Make sure there's no hardcoded exception messages, only translated ones

v0.0.1 2024-11-26 15:35 UTC

This package is auto-updated.

Last update: 2024-12-27 04:19:26 UTC


README

composer require --dev savinmikhail/symfony-translatable-exceptions

Usage

In your psalm.xml add the following lines

    <plugins>
        <pluginClass class="SavinMikhail\TranslatableExceptionsPlugin\Plugin"/>
    </plugins>

Output

ERROR: InvalidArgument - src/Service/Extractor/WhlExtractor.php:33:40 - Avoid hardcoding exception messages, use a translation mechanism instead. (see https://psalm.dev/004)
            throw new RuntimeException('File upload required.');

To fix this, we need to use

throw new RuntimeException(this->translator->trans('error.file_upload_required'));