DevHelper_CodeScanner is a Magento 2 module that helps developers identify bad practices and common issues in custom modules. It provides a CLI command to scan your app/code directory and reports potential problems, making your codebase safer and more maintainable.
- Direct usage of
ObjectManager - Direct instantiation with
new(except in tests) - Blocks in XML without
classortemplate - Observers listening to generic events (e.g.,
controller_action_predispatch) - Plugin
before,after, andaroundmethods withoutreturn - Usage of dangerous PHP functions (
eval,exec,shell_exec,system,passthru,proc_open,popen) - Debug functions left in code (
var_dump,print_r,die,exit)
- Copy the module to
app/code/DevHelper/CodeScannerin your Magento 2 project. - Run the following commands in your project root:
php bin/magento setup:upgrade
php bin/magento setup:di:compile- (Optional) Enable the module explicitly:
php bin/magento module:enable DevHelper_CodeScannerTo scan your custom modules, run:
php bin/magento devhelper:codescanThe command will output a table with the type of issue, module, file, and line number (if available).
- Magento 2.4.x
- PHP 8.1+
MIT or as you prefer.
Maintainer: Rodrigo Cardoso