{"id":30886679,"url":"https://github.com/smnandre/twigmetrics","last_synced_at":"2025-10-07T06:42:22.946Z","repository":{"id":311455882,"uuid":"1043764040","full_name":"smnandre/twigmetrics","owner":"smnandre","description":"TwigMetrics turns your templates into numbers: structure, lines of code, code style, complexity, maintanability ...","archived":false,"fork":false,"pushed_at":"2025-09-05T17:22:34.000Z","size":233,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-08T13:17:06.567Z","etag":null,"topics":["audit","charts","code-style","console","loc","metrics","numbers","php","quality","symfony","template","templates","tool","twig","twig-templates"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smnandre.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["smnandre"]}},"created_at":"2025-08-24T15:15:06.000Z","updated_at":"2025-09-05T17:22:29.000Z","dependencies_parsed_at":"2025-08-24T19:54:12.021Z","dependency_job_id":"5912ec30-128b-400a-aa08-393a0fdc3b8a","html_url":"https://github.com/smnandre/twigmetrics","commit_stats":null,"previous_names":["smnandre/twigmetrics"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/smnandre/twigmetrics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smnandre%2Ftwigmetrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smnandre%2Ftwigmetrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smnandre%2Ftwigmetrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smnandre%2Ftwigmetrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smnandre","download_url":"https://codeload.github.com/smnandre/twigmetrics/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smnandre%2Ftwigmetrics/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278734435,"owners_count":26036404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audit","charts","code-style","console","loc","metrics","numbers","php","quality","symfony","template","templates","tool","twig","twig-templates"],"created_at":"2025-09-08T13:08:44.277Z","updated_at":"2025-10-07T06:42:22.941Z","avatar_url":"https://github.com/smnandre.png","language":"PHP","funding_links":["https://github.com/sponsors/smnandre"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n\u003ch1\u003eTwig 🌿 Metrics\u003c/h1\u003e\n\nAnalyze your Twig templates and get a clear picture of their most important metrics\n\n\u003cimg src=\"./docs/metrics.png\" alt=\"Twig Metrics\" width=\"100%\" /\u003e\n\n---\n\n\u0026nbsp; ![PHP Version](https://img.shields.io/badge/PHP-8.3+-2e7d32?logoColor=6AB76E\u0026labelColor=010)\n\u0026nbsp; ![CI](https://img.shields.io/github/actions/workflow/status/smnandre/twigmetrics/CI.yaml?branch=main\u0026label=Tests\u0026logoColor=white\u0026logoSize=auto\u0026labelColor=010\u0026color=388e3c)\n\u0026nbsp; ![Release](https://img.shields.io/github/v/release/smnandre/twigmetrics?label=Stable\u0026logoColor=white\u0026logoSize=auto\u0026labelColor=010\u0026color=43a047)\n\u0026nbsp; [![GitHub Sponsors](https://img.shields.io/github/sponsors/smnandre?logo=github-sponsors\u0026logoColor=66bb6a\u0026logoSize=auto\u0026label=%20Sponsor\u0026labelColor=010\u0026color=a5d6a7)](https://github.com/sponsors/smnandre)\n\u0026nbsp; ![License](https://img.shields.io/github/license/smnandre/twigmetrics?label=License\u0026logoColor=white\u0026logoSize=auto\u0026labelColor=010\u0026color=2e7d32)\n\n\u003c/div\u003e\n\n---\n\n\u003e [!WARNING] \n\u003e TwigMetrics is in active development. Use with caution, and expect things\n\u003e to change quickly.\n\nThis project is a melting pot of code or ideas I had while working on\nvarious Symfony projects. I'm releasing it as a standalone tool in case\nit can be useful to others. \n\nDepending on the level of interest and feedback, I have plans to expand\nit into a more reliable and feature-rich tool. \n\n## What it does\n\nTwigMetrics scans a directory of `.twig` templates and produces a full report:\n\n- **Template overview**: number of files, directories, lines, characters\n- **Code style**: average line length, comment ratio, indentation, formatting\n- **Callables**: functions, filters, variables, macros, blocks, tests\n- **Architecture**: includes, extends, embeds, imports, inheritance depth\n- **Complexity**: logical depth, IF/ELSE/LOOP counts, nesting\n- **Maintainability**: large files, high complexity hotspots, risk scores\n- **Visual output**: ASCII tables and gauges directly in your terminal\n\n```bash\n$ bin/twigmetrics analyze templates/\n\n\n  ╭─ Template Files ─────╮  ╭─ Logical Comp... ────╮  ╭─ Twig Callables ─────╮\n  │  ● ● ● ● ○ ○      C  │  │  ● ● ● ● ● ○      B  │  │  ● ● ● ● ● ○      B  │\n  ╰──────────────────────╯  ╰──────────────────────╯  ╰──────────────────────╯\n\n  ╭─ Code Style ─────────╮  ╭─ Architecture ───────╮  ╭─ Maintainability ────╮\n  │  ● ● ● ● ● ○      C  │  │  ● ● ● ● ● ○      B  │  │  ● ● ● ● ● ●      A+ │\n  ╰──────────────────────╯  ╰──────────────────────╯  ╰──────────────────────╯\n```\n\nSee examples of each section in the [Usage](#usage) section below.\n\n## Installation\n\n### Global (soon)\n\n\u003e [!TIP]\n\u003e A PHAR release is planned, so you’ll be able to install it globally.\n\n### Composer\n\n```\ncomposer require --dev smnandre/twigmetrics\n```\n\n### From source\n\n```\ngit clone https://github.com/smnandre/twigmetrics.git\ncd twigmetrics\ncomposer install\n```\n\n## Usage\n\nTo analyze a directory of Twig templates, run:\n\n```\nvendor/bin/twigmetrics path/to/templates\n```\n\n## Twig Metrics\n\n### Template Files\n\n```\n  ╭─ Template Files ───────────────────────────────────────────────────────────╮\n  │                                                                            │\n  │   Total Templates ........... 188      Total Lines .............. 11,213   │\n  │   Average Lines/File ....... 59.6      Median Lines ................. 48   │\n  │   Size Coefficient (CV) .... 0.77      Gini Index ................ 0.380   │\n  │   Directories ................ 19      Characters ............... 503.8k   │\n  │                                                                            │\n  ╰────────────────────────────────────────────────────────────────────────────╯\n```\n\n### Logical Complexity\n\n```\n  ╭─ Logical Complexity ───────────────────────────────────────────────────────╮\n  │                                                                            │\n  │   Avg Complexity ............. 8.3      Max Complexity .............. 79   │\n  │   Avg Depth .................. 1.2      Max Depth .................... 6   │\n  │   IFs/Template ............... 1.3      FORs/Template .............. 0.6   │\n  │                                                                            │\n  ╰────────────────────────────────────────────────────────────────────────────╯\n```\n\n### Twig Callables\n\n```\n  ╭─ Twig Callables ───────────────────────────────────────────────────────────╮\n  │                                                                            │\n  │   Total Calls ............. 4,632      Unique Functions ............. 23   │\n  │   Unique Filters ............. 32      Unique Tests .................. 7   │\n  │   Funcs/Template ............ 2.9      Filters/Template ........... 18.9   │\n  │                                                                            │\n  ╰────────────────────────────────────────────────────────────────────────────╯\n```\n\n### Code Style\n\n```\n  ╭─ Code Style ───────────────────────────────────────────────────────────────╮\n  │                                                                            │\n  │   Avg Line Length ........... 41.0      Max Line Length ............ 217   │\n  │   Indent Consistency ...... 100.0%      P95 Length ................. 217   │\n  │   Consistency Score ........ 92.7%      Style Violations ........... 128   │\n  │   Comments/Template .......... 0.6      Mixed Indentation ............ 0   │\n  │                                                                            │\n  ╰────────────────────────────────────────────────────────────────────────────╯\n```\n\n### Architecture\n\n```\n  ╭─ Architecture ─────────────────────────────────────────────────────────────╮\n  │                                                                            │\n  │   Imports/Template ......... 0.00      Extends/Template ........... 0.22   │\n  │   Avg Inherit Depth ......... 0.2      Includes/Template .......... 0.57   │\n  │   Embeds/Template .......... 0.04      Blocks/Template ............ 1.13   │\n  │                                                                            │\n  ╰────────────────────────────────────────────────────────────────────────────╯\n```\n\n### Maintainability\n\n```\n  ╭─ Maintainability ──────────────────────────────────────────────────────────╮\n  │                                                                            │\n  │   Empty Lines Ratio ....... 10.0%      MI Average ................ 107.2   │\n  │   MI Median ............... 106.7      Comment Density ............ 1.3%   │\n  │   High Risk ................... 3      Medium Risk .................. 40   │\n  │                                                                            │\n  ╰────────────────────────────────────────────────────────────────────────────╯\n```\n\n## Contributing\n\nFeedback, issues, and pull requests are very welcome!\n* Issues: [github.com/smnandre/twigmetrics/issues](https://github.com/smnandre/twigmetrics/issues)\n* Pull Requests: [github.com/smnandre/twigmetrics/pulls](https://github.com/smnandre/twigmetrics/pulls)\n\n## License\n\n[Twig Metrics](https://github.com/smnandre/twigmetrics) is licensed under the MIT \nLicense. See the [LICENSE](./LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmnandre%2Ftwigmetrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmnandre%2Ftwigmetrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmnandre%2Ftwigmetrics/lists"}