From d0219bd9c9f7d085cc986a7552782022b8bd749e Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 26 Jul 2024 07:33:21 -0400 Subject: [PATCH 1/9] documentation tweaks. --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f4ddad0..3572028 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,10 @@ A number of metrics-related functions are accessible via the command line. ### Annotate -Use to annotate source code with metric information from a `coverage.xml` file. -Use with your CI process to keep your metrics in front of you as you develop. +Use to annotate source code with metric information from a `coverage.xml` file, +like the ones you can generate with +[PHPUnit](https://docs.phpunit.de/en/10.5/code-coverage.html). Use with your CI +process to keep your metrics in front of you as you develop. ```shell php ./vendor/bin/metrics annotate «path to coverage.xml» «path to source file» From 7ae477cef62ebc7be41a90b9ff3d575fc2e230dc Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 26 Jul 2024 07:46:57 -0400 Subject: [PATCH 2/9] documentation/todo. --- README.md | 11 ++++------- TODO.txt | 7 +++++++ 2 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 TODO.txt diff --git a/README.md b/README.md index 3572028..7ede749 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # Metrics -A package of utilities for dealing with coverage metrics in PHP, and annotating -your source files therefrom. +A command line utility for making use of coverage metrics in PHP. Chiefly, +allows you to update your source code with docblock annotations that show method +coverage/complexity. ## Installation @@ -9,11 +10,7 @@ your source files therefrom. composer require logicbrush/metrics ``` -## Command Line Functions - -A number of metrics-related functions are accessible via the command line. - -### Annotate +## Usage Use to annotate source code with metric information from a `coverage.xml` file, like the ones you can generate with diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 0000000..9d6a8e6 --- /dev/null +++ b/TODO.txt @@ -0,0 +1,7 @@ +# A list of things to do, in taskpaper format... + +Version 0.4.0: + - PHP 8.2 support. + - Update documenation. + +Archive: \ No newline at end of file From 3ddc5a3fabefa6a8d0760671c2f0482998c4dd2e Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 26 Jul 2024 07:47:09 -0400 Subject: [PATCH 3/9] tidy config. --- .phptidy-config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.phptidy-config.php b/.phptidy-config.php index fe20343..0b401ad 100644 --- a/.phptidy-config.php +++ b/.phptidy-config.php @@ -4,6 +4,6 @@ $fix_round_bracket_space = true; $add_file_docblock = false; $add_function_docblocks = true; -$add_doctags = true; +$add_doctags = false; $fix_docblock_format = true; $fix_docblock_space = true; From 8ba8959d69c46fc38f8afcdd7054b444b5347c20 Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 26 Jul 2024 07:52:09 -0400 Subject: [PATCH 4/9] documentation. --- README.md | 10 +++------- TODO.txt | 1 + 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7ede749..270f08f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # Metrics A command line utility for making use of coverage metrics in PHP. Chiefly, -allows you to update your source code with docblock annotations that show method -coverage/complexity. +allows you to update your source code with docblock annotations that present +method coverage/complexity. Use with your CI process to keep your metrics in +front of you as you develop. ## Installation @@ -12,11 +13,6 @@ composer require logicbrush/metrics ## Usage -Use to annotate source code with metric information from a `coverage.xml` file, -like the ones you can generate with -[PHPUnit](https://docs.phpunit.de/en/10.5/code-coverage.html). Use with your CI -process to keep your metrics in front of you as you develop. - ```shell php ./vendor/bin/metrics annotate «path to coverage.xml» «path to source file» ``` diff --git a/TODO.txt b/TODO.txt index 9d6a8e6..d53c69b 100644 --- a/TODO.txt +++ b/TODO.txt @@ -3,5 +3,6 @@ Version 0.4.0: - PHP 8.2 support. - Update documenation. + - Rector support. Archive: \ No newline at end of file From aa2a0267c36f82861324874503ced05b951a5479 Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 26 Jul 2024 07:53:41 -0400 Subject: [PATCH 5/9] adding php 8.2 to the matrix. --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5df0228..81a6802 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,8 @@ jobs: fail-fast: false matrix: include: + - operating-system: 'ubuntu-latest' + php-version: '8.2' - operating-system: 'ubuntu-latest' php-version: '8.1' - operating-system: 'ubuntu-latest' From 95fb6b76f5d62f01ef22b6cc63273759f3009c5d Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 26 Jul 2024 08:05:54 -0400 Subject: [PATCH 6/9] setup rector. --- .github/workflows/t.yml | 2 ++ README.md | 8 ++--- TODO.txt | 2 +- composer.json | 3 +- rector.php | 32 ++++++++++++++++++++ src/Metrics/Annotator.php | 8 ++--- src/Metrics/Bootstrap.php | 15 ++++------ src/Metrics/Impl/AnnotatorImpl.php | 47 +++++++++++++----------------- src/bootstrap.php | 9 +++--- 9 files changed, 75 insertions(+), 51 deletions(-) create mode 100644 rector.php diff --git a/.github/workflows/t.yml b/.github/workflows/t.yml index ce8a080..440b3c9 100644 --- a/.github/workflows/t.yml +++ b/.github/workflows/t.yml @@ -26,6 +26,8 @@ jobs: XDEBUG_MODE: coverage - run: | find src -name "*.php" -exec ./bin/metrics annotate ./coverage.xml {} \; + - run: | + ./vendor/bin/rector process src - run: | find tests -name "*.php" -exec ./vendor/bin/phptidy.php replace {} \; find src -name "*.php" -exec ./vendor/bin/phptidy.php replace {} \; diff --git a/README.md b/README.md index 270f08f..ee06f60 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # Metrics -A command line utility for making use of coverage metrics in PHP. Chiefly, -allows you to update your source code with docblock annotations that present -method coverage/complexity. Use with your CI process to keep your metrics in -front of you as you develop. +A command line utility for making better use of coverage metrics in PHP. +Chiefly, allows you to update your source code with docblock annotations that +present method coverage/complexity. Use with your CI process to keep your +metrics in front of you as you develop. ## Installation diff --git a/TODO.txt b/TODO.txt index d53c69b..9ffb7f5 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,7 +1,7 @@ # A list of things to do, in taskpaper format... Version 0.4.0: - - PHP 8.2 support. + - PHP 8.2 support. @done(24-07-26 07:56) - Update documenation. - Rector support. diff --git a/composer.json b/composer.json index 2178e38..bf0ffb8 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ }, "require-dev": { "phpunit/phpunit": "^8.0||^9.5", - "cmrcx/phptidy": "^3.3" + "cmrcx/phptidy": "^3.3", + "rector/rector": "^1.2" }, "prefer-stable": true, "autoload": { diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..f936968 --- /dev/null +++ b/rector.php @@ -0,0 +1,32 @@ +sets( [ + LevelSetList::UP_TO_PHP_72, + SetList::CODE_QUALITY, + SetList::DEAD_CODE, + ] ); + + $rectorConfig->skip( [ + RemoveUnusedPrivatePropertyRector::class, + ExplicitBoolCompareRector::class, + ] ); + + $rectorConfig->importShortClasses(); + $rectorConfig->importNames(); + +}; diff --git a/src/Metrics/Annotator.php b/src/Metrics/Annotator.php index 1317c82..23f6676 100644 --- a/src/Metrics/Annotator.php +++ b/src/Metrics/Annotator.php @@ -14,12 +14,8 @@ interface Annotator - /** - * - * @param string $clover - * @param string $file - */ - public function __construct( string $clover, string $file ); + + public function __construct( string $clover, string $file ); /** * diff --git a/src/Metrics/Bootstrap.php b/src/Metrics/Bootstrap.php index 3473382..97eeb1e 100644 --- a/src/Metrics/Bootstrap.php +++ b/src/Metrics/Bootstrap.php @@ -17,15 +17,12 @@ class Bootstrap { /** - * - * @Metrics( crap = 2, uncovered = true ) - * @param string $clover - * @param string $file - * @return unknown - */ - public static function createAnnotator( string $clover, string $file ) { - $annotator = new AnnotatorImpl( $clover, $file ); - return $annotator; + * + * @Metrics( crap = 2, uncovered = true ) + * @return unknown + */ + public static function createAnnotator( string $clover, string $file ) { + return new AnnotatorImpl( $clover, $file ); } diff --git a/src/Metrics/Impl/AnnotatorImpl.php b/src/Metrics/Impl/AnnotatorImpl.php index 2703b96..233b7b8 100644 --- a/src/Metrics/Impl/AnnotatorImpl.php +++ b/src/Metrics/Impl/AnnotatorImpl.php @@ -6,7 +6,7 @@ use SimpleXMLElement; // These constants are only defined in PHP 8.0+. -defined( 'T_NAME_QUALIFIED' ) or define( 'T_NAME_QUALIFIED', -1 ); +defined( 'T_NAME_QUALIFIED' ) || define( 'T_NAME_QUALIFIED', -1 ); /** * Metrics implementation of the Annotator interfce @@ -26,12 +26,10 @@ class AnnotatorImpl implements Annotator private $path_to_clover, $path_to_file; /** - * - * @Metrics( crap = 1 ) - * @param string $clover - * @param string $file - */ - public function __construct( string $clover, string $file ) { + * + * @Metrics( crap = 1 ) + */ + public function __construct( string $clover, string $file ) { $this->path_to_clover = $clover; $this->path_to_file = $file; } @@ -42,7 +40,7 @@ public function __construct( string $clover, string $file ) { * @Metrics( crap = 26.12 ) */ public function run() { - defined( 'STDIN' ) or die( 'command line only.' ); + defined( 'STDIN' ) || die( 'command line only.' ); $file = $this->path_to_file; @@ -108,7 +106,7 @@ public function run() { case T_WHITESPACE: break; default: - if ( ( $metrics = $this->metrics( $clover, $function, $class, $namespace ) ) !== null ) { + if ( ($metrics = $this->metrics( $clover, $function, $class, $namespace )) instanceof SimpleXMLElement ) { $this->annotate( $tokens, $key, $metrics ); } goto handle_token; @@ -124,14 +122,12 @@ public function run() { /** - * - * @Metrics( crap = 19.15 ) - * @param array $tokens (reference) - * @param int $key - * @param SimpleXMLElement $metrics - * @return unknown - */ - protected function annotate( array &$tokens, int $key, SimpleXMLElement $metrics ) { + * + * @Metrics( crap = 19.15 ) + * @param array $tokens (reference) + * @return unknown + */ + protected function annotate( array &$tokens, int $key, SimpleXMLElement $metrics ) { while ( $key >= 1 && ( $token = $tokens[--$key] ) ) { if ( is_array( $token ) ) { switch ( $token[0] ) { @@ -175,15 +171,14 @@ function( $array ) use ( &$first, $tag ) { /** - * - * @Metrics( crap = 5 ) - * @param SimpleXMLElement $clover - * @param string $function - * @param string $class - * @param string $namespace - * @return unknown - */ - protected function metrics( SimpleXMLElement $clover, ?string $function, ?string $class, ?string $namespace ): ?SimpleXMLElement { + * + * @Metrics( crap = 5 ) + * @param string $function + * @param string $class + * @param string $namespace + * @return unknown + */ + protected function metrics( SimpleXMLElement $clover, ?string $function, ?string $class, ?string $namespace ): ?SimpleXMLElement { if ( $function && $class ) { if ( $namespace ) { diff --git a/src/bootstrap.php b/src/bootstrap.php index f8f1add..bf5ac8e 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -1,5 +1,6 @@ getMessage() ); From 3a5c74d46a57cd9e42d7c277f99e9bfef50cfdbc Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 26 Jul 2024 12:06:25 +0000 Subject: [PATCH 7/9] tidy --- src/Metrics/Annotator.php | 7 ++++-- src/Metrics/Bootstrap.php | 10 ++++---- src/Metrics/Impl/AnnotatorImpl.php | 38 +++++++++++++++--------------- src/bootstrap.php | 1 + 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/Metrics/Annotator.php b/src/Metrics/Annotator.php index 23f6676..83081ae 100644 --- a/src/Metrics/Annotator.php +++ b/src/Metrics/Annotator.php @@ -14,8 +14,11 @@ interface Annotator - - public function __construct( string $clover, string $file ); + + /** + * + */ + public function __construct( string $clover, string $file ); /** * diff --git a/src/Metrics/Bootstrap.php b/src/Metrics/Bootstrap.php index 97eeb1e..f2f8721 100644 --- a/src/Metrics/Bootstrap.php +++ b/src/Metrics/Bootstrap.php @@ -17,11 +17,11 @@ class Bootstrap { /** - * - * @Metrics( crap = 2, uncovered = true ) - * @return unknown - */ - public static function createAnnotator( string $clover, string $file ) { + * + * @Metrics( crap = 2, uncovered = true ) + * @return unknown + */ + public static function createAnnotator( string $clover, string $file ) { return new AnnotatorImpl( $clover, $file ); } diff --git a/src/Metrics/Impl/AnnotatorImpl.php b/src/Metrics/Impl/AnnotatorImpl.php index 233b7b8..2ea3434 100644 --- a/src/Metrics/Impl/AnnotatorImpl.php +++ b/src/Metrics/Impl/AnnotatorImpl.php @@ -26,10 +26,10 @@ class AnnotatorImpl implements Annotator private $path_to_clover, $path_to_file; /** - * - * @Metrics( crap = 1 ) - */ - public function __construct( string $clover, string $file ) { + * + * @Metrics( crap = 1 ) + */ + public function __construct( string $clover, string $file ) { $this->path_to_clover = $clover; $this->path_to_file = $file; } @@ -106,7 +106,7 @@ public function run() { case T_WHITESPACE: break; default: - if ( ($metrics = $this->metrics( $clover, $function, $class, $namespace )) instanceof SimpleXMLElement ) { + if ( ( $metrics = $this->metrics( $clover, $function, $class, $namespace ) ) instanceof SimpleXMLElement ) { $this->annotate( $tokens, $key, $metrics ); } goto handle_token; @@ -122,12 +122,12 @@ public function run() { /** - * - * @Metrics( crap = 19.15 ) - * @param array $tokens (reference) - * @return unknown - */ - protected function annotate( array &$tokens, int $key, SimpleXMLElement $metrics ) { + * + * @Metrics( crap = 19.15 ) + * @param array $tokens (reference) + * @return unknown + */ + protected function annotate( array &$tokens, int $key, SimpleXMLElement $metrics ) { while ( $key >= 1 && ( $token = $tokens[--$key] ) ) { if ( is_array( $token ) ) { switch ( $token[0] ) { @@ -171,14 +171,14 @@ function( $array ) use ( &$first, $tag ) { /** - * - * @Metrics( crap = 5 ) - * @param string $function - * @param string $class - * @param string $namespace - * @return unknown - */ - protected function metrics( SimpleXMLElement $clover, ?string $function, ?string $class, ?string $namespace ): ?SimpleXMLElement { + * + * @Metrics( crap = 5 ) + * @param string $function + * @param string $class + * @param string $namespace + * @return unknown + */ + protected function metrics( SimpleXMLElement $clover, ?string $function, ?string $class, ?string $namespace ): ?SimpleXMLElement { if ( $function && $class ) { if ( $namespace ) { diff --git a/src/bootstrap.php b/src/bootstrap.php index bf5ac8e..fa5a5d4 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -14,6 +14,7 @@ require_once __DIR__ . '/Metrics/Bootstrap.php'; } + try { // if (version_compare(PHP_VERSION, '8.0.0', '<')) { // throw new \ErrorException('PHP Version is lower than 8.0.0. Please upgrade your runtime.'); From b6526fbf1be2b5b6fda88e22f0987781862d0244 Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 26 Jul 2024 08:18:14 -0400 Subject: [PATCH 8/9] update documentation. --- TODO.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO.txt b/TODO.txt index 9ffb7f5..e05d15d 100644 --- a/TODO.txt +++ b/TODO.txt @@ -3,6 +3,6 @@ Version 0.4.0: - PHP 8.2 support. @done(24-07-26 07:56) - Update documenation. - - Rector support. + - Rector support. @done(24-07-26 08:17) Archive: \ No newline at end of file From 446c37d52bcb6c9b8a715acb5050cea41ac7393d Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 26 Jul 2024 08:24:01 -0400 Subject: [PATCH 9/9] documentation --- TODO.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO.txt b/TODO.txt index e05d15d..fbbc586 100644 --- a/TODO.txt +++ b/TODO.txt @@ -2,7 +2,7 @@ Version 0.4.0: - PHP 8.2 support. @done(24-07-26 07:56) - - Update documenation. + - Update documenation. @done(24-07-26 08:22) - Rector support. @done(24-07-26 08:17) Archive: \ No newline at end of file