A tool to analyze the comment density and quality in PHP source code files, helping to maintain and improve code documentation quality.
- Multiple Comment Types: Supports identification and analysis of several comment types including regular, docblocks, TODOs, FIXMEs, and license information. You can configure the set of them to be evaluated.
- Detailed Reporting: Quickly find code spots where changes might be necessary.
- Quality Check: Set up a configuration file, and if thresholds aren't met, the exit code will be returned with the report.
- Configurable Reports: Get results in either console or HTML file.
- Pre-commit hook: Validate only the files that are about to be committed.
To install Comment Density Analyzer, run the following command in your terminal:
composer require --dev savinmikhail/comments-density
Analyze the comment density in your PHP files with:
php vendor/bin/comments_density analyze:comments
On installation, you can allow plugin to create its configuration file. Customize your analysis by editing a comments_density.php configuration file:
d<?php
return [
'directories' => [
'vendor',
],
'exclude' => [
'src/DTO',
],
'thresholds' => [
'docBlock' => 90,
'regular' => 5,
'todo' => 5,
'fixme' => 5,
'missingDocBlock' => 10,
'Com/LoC' => 0.1,
'CDS' => 0.1,
],
'only' => [
'missingDocblock'
],
'output' => [
'type' => 'console', // "console" or 'html'
'file' => 'output.html', // file path for HTML output
],
'missingDocblock' => [
'class' => true,
'interface' => true,
'trait' => true,
'enum' => true,
'property' => true,
'constant' => true,
'function' => true,
]
];
Contributions are welcome! Please feel free to submit a Pull Request.
This library is released under the MIT license.