From 61c84651963a273e3e99d18e16f6f71dd3c57a91 Mon Sep 17 00:00:00 2001 From: Timo Michna Date: Sun, 23 Jan 2022 22:54:13 +0100 Subject: [PATCH] Add PhpMetrics (#554) --- .gitignore | 3 +++ Makefile | 4 +++- README.md | 7 +++++++ composer.json | 1 + phpmetrics.json | 47 ++++++++++++++++++++++++++++++++++++++++++++ var/metrics/.gitkeep | 0 6 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 phpmetrics.json create mode 100644 var/metrics/.gitkeep diff --git a/.gitignore b/.gitignore index 67d82fef8..6cb17d031 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ tests/coverage .php-cs-fixer.cache .phpbench !tests/coverage/html/.gitkeep +var/metrics/ +!var/metrics/.gitkeep +junit.xml .env # IntelliJ IDEA diff --git a/Makefile b/Makefile index ba74e9f9c..3d533ad89 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ update: $(DC_RUN_PHP) env XDEBUG_MODE=off composer update test: test-unit test-integration test-unit: - $(DC_RUN_PHP) env XDEBUG_MODE=coverage vendor/bin/phpunit --testsuite unit --colors=always --coverage-text --testdox --coverage-clover coverage.clover --coverage-html=tests/coverage/html + $(DC_RUN_PHP) env XDEBUG_MODE=coverage vendor/bin/phpunit --testsuite unit --colors=always --coverage-text --testdox --coverage-clover coverage.clover --coverage-html=tests/coverage/html --log-junit=junit.xml test-integration: $(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/phpunit --testsuite integration --colors=always test-coverage: @@ -23,6 +23,8 @@ phpstan: $(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/phpstan analyse benchmark: $(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/phpbench run --report=default +phpmetrics: + $(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/phpmetrics --config=./phpmetrics.json --junit=junit.xml trace examples: FORCE docker-compose up -d --remove-orphans $(DC_RUN_PHP) php ./examples/AlwaysOnZipkinExample.php diff --git a/README.md b/README.md index 53b90b010..8bd24f214 100644 --- a/README.md +++ b/README.md @@ -241,6 +241,13 @@ make test from your bash compatible shell. This will output the test output as well as a test coverage analysis (text + html - see `tests/coverage/html`). Code that doesn't pass our currently defined tests will emit a failure in CI +## PhpMetrics +To generate a report showing a variety of metrics for the library and its classes, you can run: +```bash +make phpmetrics +``` +This will generate a HTML PhpMetrics report in the `var/metrics` directory. Make sure to run `make test` before to create the test log-file, used by the metrics report. + ## Examples ### Trace diff --git a/composer.json b/composer.json index 8e633365b..6f097be99 100644 --- a/composer.json +++ b/composer.json @@ -78,6 +78,7 @@ "phan/phan": "^5.0", "php-http/mock-client": "^1.5", "phpbench/phpbench": "^1.2", + "phpmetrics/phpmetrics": "^2.7", "phpstan/phpstan": "^1.1", "phpstan/phpstan-mockery": "^1.0", "phpstan/phpstan-phpunit": "^1.0", diff --git a/phpmetrics.json b/phpmetrics.json new file mode 100644 index 000000000..27d84fe71 --- /dev/null +++ b/phpmetrics.json @@ -0,0 +1,47 @@ +{ + "includes": [ + "src" + ], + "exclude": [ + "tests", + "proto", + "thrift" + ], + "report": { + "html": "var/metrics", + "csv": "var/metrics/metrics.csv", + "json": "var/metrics/metrics.json", + "violations": "var/metrics/violations.xml" + }, + "groups": [ + { + "name": "API", + "match": "!^OpenTelemetry\\\\API\\\\!i" + }, + { + "name": "Context", + "match": "!^OpenTelemetry\\\\Context\\\\!i" + }, + { + "name": "SDK", + "match": "!^OpenTelemetry\\\\SDK\\\\!i" + }, + { + "name": "SemConv", + "match": "!^OpenTelemetry\\\\SemConv\\\\!i" + }, + { + "name": "Contrib", + "match": "!^OpenTelemetry\\\\Contrib\\\\!i" + } + ], + "plugins": { + "git": { + "binary": "git" + }, + "junit": { + "file": "junit.xml" + } + }, + "extensions": [ "php" ] +} diff --git a/var/metrics/.gitkeep b/var/metrics/.gitkeep new file mode 100644 index 000000000..e69de29bb