{"id":13768482,"url":"https://github.com/povils/phpmnd","last_synced_at":"2026-02-21T22:09:15.094Z","repository":{"id":20134156,"uuid":"88907232","full_name":"povils/phpmnd","owner":"povils","description":"PHP Magic Number Detector","archived":false,"fork":false,"pushed_at":"2026-01-06T19:00:58.000Z","size":422,"stargazers_count":578,"open_issues_count":21,"forks_count":46,"subscribers_count":11,"default_branch":"master","last_synced_at":"2026-01-11T18:28:25.811Z","etag":null,"topics":["analysis","automation","checker","clean-code","cli","detector","magic-numbers","php","static-analysis"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/povils.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-04-20T20:22:17.000Z","updated_at":"2026-01-06T19:00:50.000Z","dependencies_parsed_at":"2025-12-14T11:04:38.749Z","dependency_job_id":null,"html_url":"https://github.com/povils/phpmnd","commit_stats":{"total_commits":153,"total_committers":32,"mean_commits":4.78125,"dds":0.7777777777777778,"last_synced_commit":"230775dcaf6ef65b3f4ed1dcae320bfb3fc7575a"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/povils/phpmnd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/povils%2Fphpmnd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/povils%2Fphpmnd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/povils%2Fphpmnd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/povils%2Fphpmnd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/povils","download_url":"https://codeload.github.com/povils/phpmnd/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/povils%2Fphpmnd/sbom","scorecard":{"id":742349,"data":{"date":"2025-08-11","repo":{"name":"github.com/povils/phpmnd","commit":"1c45028bedcc041d2c78151df6f38eddc1ac7420"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":5,"checks":[{"name":"Code-Review","score":10,"reason":"all changesets reviewed","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-22T17:46:41.973Z","repository_id":20134156,"created_at":"2025-08-22T17:46:41.973Z","updated_at":"2025-08-22T17:46:41.973Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29694975,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T18:18:25.093Z","status":"ssl_error","status_checked_at":"2026-02-21T18:18:22.435Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analysis","automation","checker","clean-code","cli","detector","magic-numbers","php","static-analysis"],"created_at":"2024-08-03T16:01:21.978Z","updated_at":"2026-02-21T22:09:15.069Z","avatar_url":"https://github.com/povils.png","language":"PHP","readme":"# PHP Magic Number Detector (PHPMND)\n\n[![Minimum PHP version: 7.4.0](https://img.shields.io/badge/php-7.4.0%2B-blue.svg)](https://packagist.org/packages/povils/phpmnd)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/povils/phpmnd/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/povils/phpmnd/?branch=master)\n[![License](https://poser.pugx.org/povils/phpmnd/license)](https://packagist.org/packages/povils/phpmnd)\n[![CI](https://github.com/povils/phpmnd/workflows/CI/badge.svg?branch=master)](https://github.com/povils/phpmnd)\n\n`phpmnd` is a tool that aims to **help** you to detect magic numbers in your PHP code. By default 0 and 1 are not considered to be magic numbers.\n\n## What is a magic number?\nA magic number is a numeric literal that is not defined as a constant, but which may change at a later stage, and therefore can be hard to update. It's considered a bad programming practice to use numbers directly in any source code without an explanation. In most cases this makes programs harder to read, understand, and maintain.\n\nConsider the following hypothetical code:\n\n```php\nclass Foo\n{\n    public function setPassword($password)\n    {\n         // don't do this\n         if (mb_strlen($password) \u003e 7) {\n              throw new InvalidArgumentException(\"password\");\n         }\n    }\n}\n```\nwhich should be refactored to:\n```php\nclass Foo\n{\n    const MAX_PASSWORD_LENGTH = 7; // not const SEVEN = 7 :)\n\n    public function setPassword($password)\n    {\n         if (mb_strlen($password) \u003e self::MAX_PASSWORD_LENGTH) {\n              throw new InvalidArgumentException(\"password\");\n         }\n    }\n}\n```\nThis clearly improves the code readability and also reduces its maintenance cost.\n\nOf course not every literal number is a magic number.\n```php\n$is_even = $number % 2 === 0\n```\nSurely in this case the number 2 is not a magic number.\n\n***My rule of thumb:***\n```\nIf the number came from business specs and is used directly - it's a magic number.\n```\n## Installation\n\n### Locally\n\nYou can add this tool as a local, per-project, development dependency to your project by using [Composer](https://getcomposer.org/):\n\n```bash\n$ composer require --dev povils/phpmnd\n```\n\nAfterwards you can then invoke it using the `vendor/bin/phpmnd` executable.\n\n### Globally\nTo install it globally simply run:\n\n```bash\n$ composer global require povils/phpmnd\n```\n\nAfterwards make sure you have the global Composer binaries directory in your ``PATH``. Example for some Unix systems:\n\n```bash\n$ export PATH=\"$PATH:$HOME/.composer/vendor/bin\"\n```\n\n## Usage Example\n\n#### Demo\n\n![demo](./demo.gif)\n\n#### Basic usage\n\n```bash\n$ phpmnd wordpress --ignore-numbers=2,-1 --ignore-funcs=round,sleep --exclude=tests --progress \\\n--extensions=default_parameter,-return,argument\n```\n\nThe ``--allow-array-mapping`` option allow keys as strings when using \"array\" extension.\n\nThe ``--exclude-file`` option will exclude a file from the code analysis. Multiple values are allowed.\n\nThe ``--exclude-path`` option will exclude a path, which must be relative to the source, from the code analysis. Multiple values are allowed.\n\nThe ``--exclude`` option will exclude a directory, which must be relative to the source, from the code analysis. Multiple values are allowed (e.g. --exclude=tests --exclude=examples).\n\nThe ``--extensions`` option lets you extend the code analysis. The provided extensions must be comma separated.\n\nThe ``--hint`` option will suggest replacements for magic numbers based on your codebase constants.\n\nThe ``--ignore-funcs`` option will exclude a list of comma separated functions from the code analysis, when using the \"argument\" extension. Defaults to `intval`, `floatval`, `strval`.\n\nThe ``--ignore-numbers`` option will exclude a list of comma separated numbers from the code analysis.\n\nThe ``--ignore-strings`` option will exclude strings from the code analysis, when using the \"strings\" option.\n\nThe ``--include-numeric-string`` option forces numeric strings such as \"1234\" to also be treated as a number.\n\nThe ``--progress`` option will display a progress bar.\n\nThe ``--strings`` option will include strings literal search in code analysis.\n\nThe ``--suffixes`` option will configure a comma separated list of valid source code filename extensions.\n\nThe ``--whitelist`` option will only process the files listed in the file specified. This is useful for incremental analysis.\n\nThe ``--xml-output`` option will generate an report in an Xml format to the path specified by the option.\n**By default it analyses conditions, return statements, and switch cases.**\n\n#### Extensions\n\n* **argument**\n```php\nround($number, 4);\n```\n* **array**\n```php\n$array = [200, 201];\n```\n* **assign**\n```php\n$var = 10;\n```\n* **default_parameter**\n```php\nfunction foo($default = 3);\n```\n* **operation**\n```php\n$bar = $foo * 20;\n```\n* **property**\n```php\nprivate $bar = 10;\n```\n* **return (default)**\n```php\nreturn 5;\n```\n * **condition (default)**\n```php\n$var \u003c 7;\n```\n* **switch_case (default)**\n```php\ncase 3;\n```\n* **all**\nTo include all extensions.\n\nIf extensions start with a minus, it means that these will be removed from the code analysis. I would recommend to clean up your code by using the default extension before using any of these extensions.\n\n## Ignoring a number from analysis\n\nSometimes magic numbers are required. For example implementing a known mathematical formula, by default `intval`, `floatval` and `strval` mark a number as not magic.\n\neg\n\n```\n$percent  = $number / 100;\n```\nwould show 100 as a magic number\n\n```\n$percent = $number / intval(100);\n```\nwould mark 100 as not magic.\n\n## Contributing\n\nPlease see [CONTRIBUTING.md](CONTRIBUTING.md) for more information.\n\n## License\n\nThe MIT License (MIT). Please see [LICENSE](LICENSE) for more information.\n","funding_links":[],"categories":["Table of Contents","PHP","Programming Languages"],"sub_categories":["Code Analysis"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpovils%2Fphpmnd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpovils%2Fphpmnd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpovils%2Fphpmnd/lists"}