Description
phpmnd, short for PHP Magic Number Detector, is a tool that helps you find magic numbers in PHP code. A magic number is a numeric literal used directly in code instead of a named constant, which can be hard to update and to understand later. By default, 0 and 1 are not treated as magic numbers. The README explains the idea with examples of code that should be refactored to use a constant, and notes that not every literal number is a magic number. You can install it as a per-project development dependency with Composer and run it from vendor/bin/phpmnd, or install it globally and add the global Composer binaries directory to your PATH. The usage section shows basic runs and several options. The --allow-array-mapping option allows string keys when the array extension is used. The --exclude-file, --exclude-path and --exclude options skip a file, a path relative to the source, or a directory, and each can be repeated. A demo is included in the README.…
Highlights
- Detects magic numbers in PHP code
- 0 and 1 allowed by default
- Installs locally or globally with Composer
- Exclude files, paths or directories
- Array key mapping option
Ratings & Reviews
No ratings yet
Be the first to rate Phpmnd.
People also visit

PhpCodeArcheology/PhpCodeArcheology
PHP static analysis: code quality metrics, problem detection
Phpmnd FAQ
What is phpmnd?
A PHP tool that detects magic numbers, which are numeric literals that are usually better as named constants.
How do I install it?
Add it to a project with Composer as a development dependency and run vendor/bin/phpmnd. Or install it globally and add the Composer global bin directory to your PATH.
Are 0 and 1 flagged?
No. By default, 0 and 1 are not considered magic numbers.
How do I skip files or folders?
Use --exclude-file, --exclude-path or --exclude. Each accepts multiple values, and paths are relative to the source.
Does it flag every number?
No. The README says not every literal number is a magic number, and gives an example where 2 is fine.
What are the best Phpmnd alternatives?
Popular alternatives to Phpmnd include Phpinsights, PHP_CodeSniffer and Checkpoint. See all Phpmnd alternatives










