PHPackages                             smnandre/twigmetrics - 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. [CLI &amp; Console](/categories/cli)
4. /
5. smnandre/twigmetrics

ActiveProject[CLI &amp; Console](/categories/cli)

smnandre/twigmetrics
====================

Twig template analyzer for PHP: structure, style, complexity, and maintainability metrics at a glance

v1.1.0(8mo ago)856111MITPHPPHP &gt;=8.3CI passing

Since Aug 24Pushed 8mo agoCompare

[ Source](https://github.com/smnandre/twigmetrics)[ Packagist](https://packagist.org/packages/smnandre/twigmetrics)[ GitHub Sponsors](https://github.com/smnandre)[ RSS](/packages/smnandre-twigmetrics/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (6)Versions (5)Used By (1)

Twig 🌿 Metrics
==============

[](#twig--metrics)

Analyze your Twig templates and get a clear picture of their most important metrics

[![Twig Metrics](./docs/metrics.png)](./docs/metrics.png)---

 [![PHP Version](https://camo.githubusercontent.com/8f212facb5a00fc9c5e2601fb47f474a13088807809aaf8ea437805277624fae/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332b2d3265376433323f6c6f676f436f6c6f723d364142373645266c6162656c436f6c6f723d303130)](https://camo.githubusercontent.com/8f212facb5a00fc9c5e2601fb47f474a13088807809aaf8ea437805277624fae/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332b2d3265376433323f6c6f676f436f6c6f723d364142373645266c6162656c436f6c6f723d303130) [![CI](https://camo.githubusercontent.com/262a62120aa1f45e200908e7ee404fa8cae397711b7df6b12fa8323a2ad25215/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736d6e616e6472652f747769676d6574726963732f43492e79616d6c3f6272616e63683d6d61696e266c6162656c3d5465737473266c6f676f436f6c6f723d7768697465266c6f676f53697a653d6175746f266c6162656c436f6c6f723d30313026636f6c6f723d333838653363)](https://camo.githubusercontent.com/262a62120aa1f45e200908e7ee404fa8cae397711b7df6b12fa8323a2ad25215/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736d6e616e6472652f747769676d6574726963732f43492e79616d6c3f6272616e63683d6d61696e266c6162656c3d5465737473266c6f676f436f6c6f723d7768697465266c6f676f53697a653d6175746f266c6162656c436f6c6f723d30313026636f6c6f723d333838653363) [![Release](https://camo.githubusercontent.com/4527f7ce313dba0a9a9e79aa11f31f6149dcc03ccdee5e1addc32e108394481d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f736d6e616e6472652f747769676d6574726963733f6c6162656c3d537461626c65266c6f676f436f6c6f723d7768697465266c6f676f53697a653d6175746f266c6162656c436f6c6f723d30313026636f6c6f723d343361303437)](https://camo.githubusercontent.com/4527f7ce313dba0a9a9e79aa11f31f6149dcc03ccdee5e1addc32e108394481d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f736d6e616e6472652f747769676d6574726963733f6c6162656c3d537461626c65266c6f676f436f6c6f723d7768697465266c6f676f53697a653d6175746f266c6162656c436f6c6f723d30313026636f6c6f723d343361303437) [![GitHub Sponsors](https://camo.githubusercontent.com/4cd34878abecbe785785110fd775ebfaa34e5bb3812b45e661a42c5e632a0f0c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73706f6e736f72732f736d6e616e6472653f6c6f676f3d6769746875622d73706f6e736f7273266c6f676f436f6c6f723d363662623661266c6f676f53697a653d6175746f266c6162656c3d25323053706f6e736f72266c6162656c436f6c6f723d30313026636f6c6f723d613564366137)](https://github.com/sponsors/smnandre) [![License](https://camo.githubusercontent.com/9ec085e145e2651d80fc7d6525676d7ec259ab6d486c3ae6d72840f4ce766f82/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f736d6e616e6472652f747769676d6574726963733f6c6162656c3d4c6963656e7365266c6f676f436f6c6f723d7768697465266c6f676f53697a653d6175746f266c6162656c436f6c6f723d30313026636f6c6f723d326537643332)](https://camo.githubusercontent.com/9ec085e145e2651d80fc7d6525676d7ec259ab6d486c3ae6d72840f4ce766f82/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f736d6e616e6472652f747769676d6574726963733f6c6162656c3d4c6963656e7365266c6f676f436f6c6f723d7768697465266c6f676f53697a653d6175746f266c6162656c436f6c6f723d30313026636f6c6f723d326537643332)

---

Warning

TwigMetrics is in active development. Use with caution, and expect things to change quickly.

This project is a melting pot of code or ideas I had while working on various Symfony projects. I'm releasing it as a standalone tool in case it can be useful to others.

Depending on the level of interest and feedback, I have plans to expand it into a more reliable and feature-rich tool.

What it does
------------

[](#what-it-does)

TwigMetrics scans a directory of `.twig` templates and produces a full report:

- **Template overview**: number of files, directories, lines, characters
- **Code style**: average line length, comment ratio, indentation, formatting
- **Callables**: functions, filters, variables, macros, blocks, tests
- **Architecture**: includes, extends, embeds, imports, inheritance depth
- **Complexity**: logical depth, IF/ELSE/LOOP counts, nesting
- **Maintainability**: large files, high complexity hotspots, risk scores
- **Visual output**: ASCII tables and gauges directly in your terminal

```
$ bin/twigmetrics analyze templates/

  ╭─ Template Files ─────╮  ╭─ Logical Comp... ────╮  ╭─ Twig Callables ─────╮
  │  ● ● ● ● ○ ○      C  │  │  ● ● ● ● ● ○      B  │  │  ● ● ● ● ● ○      B  │
  ╰──────────────────────╯  ╰──────────────────────╯  ╰──────────────────────╯

  ╭─ Code Style ─────────╮  ╭─ Architecture ───────╮  ╭─ Maintainability ────╮
  │  ● ● ● ● ● ○      C  │  │  ● ● ● ● ● ○      B  │  │  ● ● ● ● ● ●      A+ │
  ╰──────────────────────╯  ╰──────────────────────╯  ╰──────────────────────╯
```

See examples of each section in the [Usage](#usage) section below.

Installation
------------

[](#installation)

### Global (soon)

[](#global-soon)

Tip

A PHAR release is planned, so you’ll be able to install it globally.

### Composer

[](#composer)

```
composer require --dev smnandre/twigmetrics

```

### From source

[](#from-source)

```
git clone https://github.com/smnandre/twigmetrics.git
cd twigmetrics
composer install

```

Usage
-----

[](#usage)

To analyze a directory of Twig templates, run:

```
vendor/bin/twigmetrics path/to/templates

```

Twig Metrics
------------

[](#twig-metrics)

### Template Files

[](#template-files)

```
  ╭─ Template Files ───────────────────────────────────────────────────────────╮
  │                                                                            │
  │   Total Templates ........... 188      Total Lines .............. 11,213   │
  │   Average Lines/File ....... 59.6      Median Lines ................. 48   │
  │   Size Coefficient (CV) .... 0.77      Gini Index ................ 0.380   │
  │   Directories ................ 19      Characters ............... 503.8k   │
  │                                                                            │
  ╰────────────────────────────────────────────────────────────────────────────╯

```

### Logical Complexity

[](#logical-complexity)

```
  ╭─ Logical Complexity ───────────────────────────────────────────────────────╮
  │                                                                            │
  │   Avg Complexity ............. 8.3      Max Complexity .............. 79   │
  │   Avg Depth .................. 1.2      Max Depth .................... 6   │
  │   IFs/Template ............... 1.3      FORs/Template .............. 0.6   │
  │                                                                            │
  ╰────────────────────────────────────────────────────────────────────────────╯

```

### Twig Callables

[](#twig-callables)

```
  ╭─ Twig Callables ───────────────────────────────────────────────────────────╮
  │                                                                            │
  │   Total Calls ............. 4,632      Unique Functions ............. 23   │
  │   Unique Filters ............. 32      Unique Tests .................. 7   │
  │   Funcs/Template ............ 2.9      Filters/Template ........... 18.9   │
  │                                                                            │
  ╰────────────────────────────────────────────────────────────────────────────╯

```

### Code Style

[](#code-style)

```
  ╭─ Code Style ───────────────────────────────────────────────────────────────╮
  │                                                                            │
  │   Avg Line Length ........... 41.0      Max Line Length ............ 217   │
  │   Indent Consistency ...... 100.0%      P95 Length ................. 217   │
  │   Consistency Score ........ 92.7%      Style Violations ........... 128   │
  │   Comments/Template .......... 0.6      Mixed Indentation ............ 0   │
  │                                                                            │
  ╰────────────────────────────────────────────────────────────────────────────╯

```

### Architecture

[](#architecture)

```
  ╭─ Architecture ─────────────────────────────────────────────────────────────╮
  │                                                                            │
  │   Imports/Template ......... 0.00      Extends/Template ........... 0.22   │
  │   Avg Inherit Depth ......... 0.2      Includes/Template .......... 0.57   │
  │   Embeds/Template .......... 0.04      Blocks/Template ............ 1.13   │
  │                                                                            │
  ╰────────────────────────────────────────────────────────────────────────────╯

```

### Maintainability

[](#maintainability)

```
  ╭─ Maintainability ──────────────────────────────────────────────────────────╮
  │                                                                            │
  │   Empty Lines Ratio ....... 10.0%      MI Average ................ 107.2   │
  │   MI Median ............... 106.7      Comment Density ............ 1.3%   │
  │   High Risk ................... 3      Medium Risk .................. 40   │
  │                                                                            │
  ╰────────────────────────────────────────────────────────────────────────────╯

```

Contributing
------------

[](#contributing)

Feedback, issues, and pull requests are very welcome!

- Issues: [github.com/smnandre/twigmetrics/issues](https://github.com/smnandre/twigmetrics/issues)
- Pull Requests: [github.com/smnandre/twigmetrics/pulls](https://github.com/smnandre/twigmetrics/pulls)

License
-------

[](#license)

[Twig Metrics](https://github.com/smnandre/twigmetrics) is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.

###  Health Score

41

—

FairBetter than 88% of packages

Maintenance64

Regular maintenance activity

Popularity25

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 78.6% 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 ~2 days

Total

3

Last Release

253d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8951d49b371d210280a58ce48969a07d1f49924810f8a1fab3a9343eb46fdc9?d=identicon)[simonandre](/maintainers/simonandre)

---

Top Contributors

[![smnandre](https://avatars.githubusercontent.com/u/1359581?v=4)](https://github.com/smnandre "smnandre (11 commits)")[![raphael-geffroy](https://avatars.githubusercontent.com/u/81738559?v=4)](https://github.com/raphael-geffroy "raphael-geffroy (3 commits)")

---

Tags

auditchartscode-styleconsolelocmetricsnumbersphpqualitysymfonytemplatetemplatestooltwigtwig-templatesclistatic analysisCode styletwigMetricstemplatecode qualitycomplexityconsole-applicationloclines-of-code

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/smnandre-twigmetrics/health.svg)

```
[![Health](https://phpackages.com/badges/smnandre-twigmetrics/health.svg)](https://phpackages.com/packages/smnandre-twigmetrics)
```

###  Alternatives

[n98/magerun

Tools for managing Magento projects and installations

1.4k264.7k7](/packages/n98-magerun)[n98/magerun2

Tools for managing Magento projects and installations

928244.3k6](/packages/n98-magerun2)

PHPackages © 2026

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