2017 © Pedro Peláez
 

yii2-extension yii2-codestat

Statistic of code usage inspired by Laravel Stats

image

insolita/yii2-codestat

Statistic of code usage inspired by Laravel Stats

  • Sunday, November 26, 2017
  • by Insolita
  • Repository
  • 2 Watchers
  • 11 Stars
  • 48 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Yii2 Code Statistic

Build Status Scrutinizer Code Quality SensioLabsInsight, (*1)

screenshot, (*2)

Based on phploc/phploc, (*3)

Installation

Either run, (*4)

composer require --dev insolita/yii2-codestat:~2.0

or add, (*5)

"insolita/yii2-codestat": "~2.0"

in require-dev section of your composer.json file., (*6)

Basic Usage

Add in console configuration file, in section modules, (*7)

php
'modules'=>[
 ....
        'codestat'=>[
            'class'=>\insolita\codestat\CodeStatModule::class,
            'scanTargets' => ['@backend/','@common/','@frontend/','@console/'],
            'exceptTargets' => ['*config*','vendor*','*web/','*runtime/','*views/','*tests/'],
        ]
    ],

scanTargets - array of path, or path aliases that will be scanned recursively exceptTargets - array of path patterns for excluding, (*8)

For checking whole list of files that will be processed, run, (*9)

./yii codestat/default/list-files

For statistic summary output run, (*10)

./yii codestat

For statistic summary output with show bad resolved files, (*11)

./yii codestat 1

Show full phploc report per each defined group, (*12)

./yii codestat/default/advanced 
./yii codestat/default/advanced WebControllers
./yii codestat/default/advanced WebControllers,RestControllers,ConsoleControllers

Show full phploc report for all matched files, (*13)

./yii codestat/default/common

Show full phploc report for custom directory, (*14)

./yii codestat/default/directory @common/models

Show full phploc report for custom file, (*15)

./yii codestat/default/file @common/lib/MySuperClass.php

List available metrics with codes, (*16)

./yii codestat/default/list-metrics

Advanced Usage

Custom Class Grouping Rules

You can extend or overwrite property 'groupRules', with supported formats, (*17)

'Group Name' => 'BaseParentClass', (*18)

where 'BaseParentClass' should by verified with (\ReflectionClass)->isSubclassOf(), (*19)

or, (*20)

'Group Name' => function(\ReflectionClass $reflection){
       //Should return true if class valid for this group, otherwise false;
  }

Final example, (*21)

php
'modules'=>[
 ....
        'codestat'=>[
            'class'=>\insolita\codestat\CodeStatModule::class,
             'groupRules' => [
                                'Jobs' => 'yii\queue\JobInterface',
                                'Handlers' => 'trntv\bus\interfaces\Handler::class',
                                'DTO' => function (\ReflectionClass $reflection) {
                                     return mb_strpos($reflection->getFileName(), 'Dto')!==false;
                                },
                                'All Tests' => function (\ReflectionClass $reflection) {
                                    return $reflection->isSubclassOf('\Codeception\Test\Unit')
                                        || StringHelper::endsWith($reflection->getName(), 'Cest');
                                },
                            ] + CodeStatModule::defaultRules(),
                    ],
        ]
    ],

Important! The order of the rules in the list matters, the base classes (\yii\base\Component and \yii\base\Object) should be at the end of the list!, (*22)

Custom code metrics

Code metrics provided by https://github.com/sebastianbergmann/phploc, has lot of variants, you can define own combination, (*23)

For actions advanced/common/directory/file you should set metrics property with array of necessary metric names, (*24)

php
'modules'=>[
 ....
        'codestat'=>[
            'class'=>\insolita\codestat\CodeStatModule::class,
            'metrics'=>['loc','lloc','classCcnAvg', 'classLlocAvg', 'methodCcnAvg']
            ]
 ]

For summary action you should provide property 'analyseCallback' in module like as, (*25)

    'analyseCallback = function($group){
               /**@var insolita\codestat\lib\collection\Group $group **/
               $metrics=$customAnalyzer->analyze($group->getFiles());
               return ['totalFiles'=>count($group->getFiles()),  'metric1'=>$metrics[some], ...etc];
     }

It should return associative array with 'metric name' => 'metric value' data and will replace internal https://github .com/Insolita/yii2-codestat/blob/7d0fc3351718b2052624ea091ff8f154fe471aeb/src/lib/CodestatService.php#L154, (*26)

And also table summary convention - if metric name contains slash "/", for summary row will be counted average value, otherwise sum, (*27)

The Versions

26/11 2017

dev-master

9999999-dev

Statistic of code usage inspired by Laravel Stats

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

yii2 code statistic

26/11 2017

1.0

1.0.0.0

Statistic of code usage inspired by Laravel Stats

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

yii2 code statistic

19/10 2017

0.0.2

0.0.2.0

Statistic of code usage inspired by Laravel Stats

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

yii2 code statistic

19/10 2017

0.0.3

0.0.3.0

Statistic of code usage inspired by Laravel Stats

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

yii2 code statistic

19/10 2017

dev-scrutinizer-patch-1

dev-scrutinizer-patch-1

Statistic of code usage inspired by Laravel Stats

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

yii2 code statistic

19/10 2017

0.0.1

0.0.1.0

Statistic of code usage inspired by Laravel Stats

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

yii2 code statistic