Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jul 26, 2024
2 parents 18cbafb + 5185314 commit 7ddedea
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/t.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {} \;
Expand Down
2 changes: 1 addition & 1 deletion .phptidy-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
# Metrics

A package of utilities for making use of coverage metrics in PHP.
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

```shell
composer require logicbrush/metrics
```

## Command Line Functions

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.
## Usage

```shell
php ./vendor/bin/metrics annotate «path to coverage.xml» «path to source file»
Expand All @@ -33,4 +29,4 @@ This will annotate your code with a `@Metrics` annotation, e.g:
public function someMethod() : void {
...
}
```
```
8 changes: 8 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# A list of things to do, in taskpaper format...

Version 0.4.0:
- PHP 8.2 support. @done(24-07-26 07:56)
- Update documenation. @done(24-07-26 08:22)
- Rector support. @done(24-07-26 08:17)

Archive:
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
32 changes: 32 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
*
* @package default
*/


declare( strict_types = 1 );

use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;

return static function ( RectorConfig $rectorConfig ): void {

$rectorConfig->sets( [
LevelSetList::UP_TO_PHP_72,
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
] );

$rectorConfig->skip( [
RemoveUnusedPrivatePropertyRector::class,
ExplicitBoolCompareRector::class,
] );

$rectorConfig->importShortClasses();
$rectorConfig->importNames();

};
3 changes: 1 addition & 2 deletions src/Metrics/Annotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ interface Annotator




/**
*
* @param string $clover
* @param string $file
*/
public function __construct( string $clover, string $file );

Expand Down
5 changes: 1 addition & 4 deletions src/Metrics/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ 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;
return new AnnotatorImpl( $clover, $file );
}


Expand Down
19 changes: 7 additions & 12 deletions src/Metrics/Impl/AnnotatorImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,8 +28,6 @@ class AnnotatorImpl implements Annotator
/**
*
* @Metrics( crap = 1 )
* @param string $clover
* @param string $file
*/
public function __construct( string $clover, string $file ) {
$this->path_to_clover = $clover;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -126,9 +124,7 @@ public function run() {
/**
*
* @Metrics( crap = 19.15 )
* @param array $tokens (reference)
* @param int $key
* @param SimpleXMLElement $metrics
* @param array $tokens (reference)
* @return unknown
*/
protected function annotate( array &$tokens, int $key, SimpleXMLElement $metrics ) {
Expand Down Expand Up @@ -177,10 +173,9 @@ function( $array ) use ( &$first, $tag ) {
/**
*
* @Metrics( crap = 5 )
* @param SimpleXMLElement $clover
* @param string $function
* @param string $class
* @param string $namespace
* @param string $function
* @param string $class
* @param string $namespace
* @return unknown
*/
protected function metrics( SimpleXMLElement $clover, ?string $function, ?string $class, ?string $namespace ): ?SimpleXMLElement {
Expand Down
10 changes: 6 additions & 4 deletions src/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Logicbrush\Metrics\Bootstrap;
/**
*
* @noRector
Expand All @@ -9,20 +10,21 @@

require_once $GLOBALS['_composer_autoload_path'];

if ( ! class_exists( 'Logicbrush\Metrics\Bootstrap' ) ) {
if ( ! class_exists( Bootstrap::class ) ) {
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.');
// }
if ( isset( $argv[1] ) && ( $argv[1] == 'annotate' ) &&
if ( isset( $argv[1] ) && ( $argv[1] === 'annotate' ) &&
isset( $argv[2] ) && ( $clover = $argv[2] ) &&
isset( $argv[3] ) && ( $file = $argv[3] ) ) {
return Logicbrush\Metrics\Bootstrap::createAnnotator( $clover, $file );
return Bootstrap::createAnnotator( $clover, $file );
}
throw new \ErrorException( 'You must include path to coverage file and file to be annotated as arg 1 and arg 2 respectively.' );
throw new ErrorException( 'You must include path to coverage file and file to be annotated as arg 1 and arg 2 respectively.' );

} catch ( Exception $e ) {
printf( $e->getMessage() );
Expand Down

0 comments on commit 7ddedea

Please sign in to comment.