PHPackages                             insolita/yii2-codestat - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. insolita/yii2-codestat

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

insolita/yii2-codestat
======================

Statistic of code usage inspired by Laravel Stats

2.0.2(7y ago)341591MITPHPPHP ^7.2

Since Oct 19Pushed 7y ago4 watchersCompare

[ Source](https://github.com/Insolita/yii2-codestat)[ Packagist](https://packagist.org/packages/insolita/yii2-codestat)[ RSS](/packages/insolita-yii2-codestat/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (6)Versions (18)Used By (0)

Yii2 Code Statistic
===================

[](#yii2-code-statistic)

[![Build Status](https://camo.githubusercontent.com/c5550bf6c548afc90c8b8d5c9ef55c4f8aeed8d3be3a39f1e7e1b419ff66a989/68747470733a2f2f7472617669732d63692e6f72672f496e736f6c6974612f796969322d636f6465737461742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Insolita/yii2-codestat)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/20c85a5f0f9a64960492b95e0fe09bb3940195962b67e5f4b436583a1da92f06/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f496e736f6c6974612f796969322d636f6465737461742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Insolita/yii2-codestat/?branch=master)[![SensioLabsInsight](https://camo.githubusercontent.com/bde8ca3cdd64c3592d013a368948a285252ea8389cd35ae4fcdcb22e45c14111/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f61326238346133392d626261652d343333302d616537352d6434363431313166393861632f736d616c6c2e706e67)](https://insight.sensiolabs.com/projects/a2b84a39-bbae-4330-ae75-d464111f98ac)

[![screenshot](codestat.png)](codestat.png)

Based on phploc/phploc

Installation
============

[](#installation)

Either run

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

```

or add

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

```

in require-dev section of your `composer.json` file.

Basic Usage
-----------

[](#basic-usage)

Add in console configuration file, in section modules

```
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

For checking whole list of files that will be processed, run

```
./yii codestat/default/list-files

```

For statistic summary output run

```
./yii codestat

```

For statistic summary output with show bad resolved files

```
./yii codestat 1

```

Show full phploc report per each defined group

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

```

Show full phploc report for all matched files

```
./yii codestat/default/common

```

Show full phploc report for custom directory

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

```

Show full phploc report for custom file

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

```

List available metrics with codes

```
./yii codestat/default/list-metrics

```

Advanced Usage
--------------

[](#advanced-usage)

#### Custom Class Grouping Rules

[](#custom-class-grouping-rules)

You can extend or overwrite property 'groupRules', with supported formats

`'Group Name' => 'BaseParentClass'`

where 'BaseParentClass' should by verified with `(\ReflectionClass)->isSubclassOf()`

or

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

```

Final example

```
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!

### Custom code metrics

[](#custom-code-metrics)

Code metrics provided by , has lot of variants, you can define own combination

For actions advanced/common/directory/file you should set metrics property with array of necessary metric names

```
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

```
    '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 .com/Insolita/yii2-codestat/blob/7d0fc3351718b2052624ea091ff8f154fe471aeb/src/lib/CodestatService.php#L154

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

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 93.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~51 days

Recently: every ~0 days

Total

12

Last Release

2565d ago

Major Versions

0.0.3 → 1.02017-11-26

1.x-dev → 2.0.02019-05-03

PHP version history (2 changes)0.0.1PHP &gt;=5.6

2.0.0PHP ^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/40f26825f8c130796e3151e6c076721cf5bb222c42148102bb31a341a1a5c789?d=identicon)[Insolita](/maintainers/Insolita)

---

Top Contributors

[![Insolita](https://avatars.githubusercontent.com/u/1847402?v=4)](https://github.com/Insolita "Insolita (70 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (5 commits)")

---

Tags

hacktoberfestcodeyii2statistic

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/insolita-yii2-codestat/health.svg)

```
[![Health](https://phpackages.com/badges/insolita-yii2-codestat/health.svg)](https://phpackages.com/packages/insolita-yii2-codestat)
```

###  Alternatives

[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1452.6k](/packages/dmstr-yii2-cookie-consent)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
