Repository navigation
Code Quality
Besides the tests, KeyAnyWhere measures its code with static analysis, mess detection, architecture rules and mutation testing, and combines them into a quality index from 0 to 100. CI fails a pull request that makes any of them worse. This page explains each tool, how to run it, and how the "ratchet" against the reference values works.
A development environment with the development dependencies. Mutation testing also needs a coverage driver (PCOV) and the test database.
| Command | Tool | What it checks |
|---|---|---|
composer stan |
PHPStan, level 8 | Types and likely bugs. |
composer md |
PHPMD (phpmd.xml.dist) |
Size, complexity and coupling (single responsibility). |
composer arquitetura |
Deptrac (deptrac.yaml) |
Layer rules; see Architecture. |
composer analise |
the three above | Only new problems fail; old debt lives in the baselines. |
composer mutacao |
coverage + Infection | Changes the code on purpose and checks that some test fails (about 2 minutes). |
composer mutacao:alteracoes |
Infection | Same, only on the lines changed since origin/main, listing the mutants that survived. |
composer qualidade |
bin/qualidade --comparar |
The quality index and the ratchet (below). |
Run the static checks:
composer analiseRun mutation testing only on what you changed:
composer mutacao:alteracoesbin/qualidade, configured by qualidade.json, scores six metrics and weighs them into an index from 0 to 100:
| Metric | Weight | Measures |
|---|---|---|
| Coverage | 20 | Lines covered by tests. |
| Mutation (MSI) | 20 | Mutants killed by the tests. |
| Types | 20 | Files without PHPStan debt. |
| Complexity | 15 | Methods within cyclomatic complexity 10 and NPath 200 (PDepend). |
| Cohesion | 10 | PHPMD. |
| Architecture | 15 | Deptrac. |
composer qualidadeThe CI job Qualidade compares each metric with qualidade-referencia.json and fails when:
- any metric drops more than 0.5 point below the reference; or
- the debt grows: PHPStan baseline plus
@phpstan-ignore, PHPMD baseline, Deptrac baseline,@SuppressWarnings.
Fix new problems instead of adding them to a baseline. When you fix old debt, regenerate the baseline and commit it with the fix:
composer stan:baselinecomposer md:baselinecomposer arquitetura:baselineImportant
When a metric improves, update qualidade-referencia.json with the values from the CI run (the job summary of your pull request), not from your computer. A few mutants depend on the local environment (config/app_local.php, config/.env): they are killed locally and escape in CI, so a reference made locally can make CI fail. composer qualidade:referencia writes the file from the current measurements.
Source code · Issues · Releases · Packagist · Online demo · Hosted edition
1. Getting started
2. Installing in production
- Overview
- Preparing the Server
- Installing KeyAnyWhere
- File Permissions
- Generating Security Keys
- Environment Variables
- Configuration Files
- Database Setup
- Insecure Password Catalog
- Web Server and HTTPS
- First-Run Setup
3. Operating your installation
4. Using KeyAnyWhere
5. Security
6. Development
7. Extending