tomasvotruba/lines 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tomasvotruba/lines

Composer 安装命令:

composer require tomasvotruba/lines

包简介

Measuring the size of PHP project and its PHP features

README 文档

README

CLI tool for quick size measure of PHP project, and real used PHP features.

Zero dependencies. Runs anywhere.


What are killer features?

  • install anywhere - PHP 7.2? PHPUnit 6? Symfony 3? Not a problem, this package has zero dependencies and works on PHP 7.2+
  • get quick overview of your project size - no details, no complexity, just lines of code
  • get easy JSON output for further processing
  • measure used PHP features in your project - how much PHP 8.0-features used? How many attributes? How many arrow function? How many union types?

Install

The package is scoped and downgraded to PHP 7.2. So you can install it anywhere with any set of dependencies:

composer require tomasvotruba/lines --dev

1. Measure Lines and Size

vendor/bin/lines measure

By default, we measure the root directory. To narrow it down, provide explicit path:

vendor/bin/lines measure src

For short output:

vendor/bin/lines measure --short

For json output, just add --json:

vendor/bin/lines measure --json

Also, you can combine them (very handy for blog posts and tweets):

vendor/bin/lines measure --short --json

For the text output, you'll get data like these:

 --------------------------------------------------- -------
  Filesystem                                          Count
 --------------------------------------------------- -------
  Directories                                            32
  Files                                                 160
 --------------------------------------------------- -------

 --------------------------------------- -------- ----------
  Lines of code                           Count    Relative
 --------------------------------------- -------- ----------
  Code                                    15 521     70.9 %
  Comments                                 6 372     29.1 %
  Total                                   21 893      100 %
 --------------------------------------- -------- ----------

 --------------------------------------------------- -------
  Structure                                           Count
 --------------------------------------------------- -------
  Namespaces                                             32
  Classes                                               134
    * Constants                                          91
    * Methods                                         1 114
  Interfaces                                             20
  Traits                                                  4
  Enums                                                   1
  Functions                                              36
  Global constants                                        0
 --------------------------------------------------- -------

 ---------------------------------------- ------- ----------
  Method access                            Count   Relative
 ---------------------------------------- ------- ----------
  Non-static                               1 058       95 %
  Static                                      56        5 %
 ---------------------------------------- ------- ----------

 ---------------------------------------- ------- ----------
  Method visibility                        Count   Relative
 ---------------------------------------- ------- ----------
  Public                                     875     78.5 %
  Protected                                   90      8.1 %
  Private                                    149     13.4 %
 ---------------------------------------- ------- ----------

Or in a json format:

{
    "filesystem": {
        "directories": 10,
        "files": 15
    },
    "lines_of_code": {
        "code": 1064,
        "code_relative": 95.4,
        "comments": 51,
        "comments_relative": 4.6,
        "total": 1115
    },
    "structure": {
        "namespaces": 11,
        "classes": 14,
        "class_methods": 88,
        "class_constants": 0,
        "interfaces": 1,
        "traits": 0,
        "enums": 0,
        "functions": 5,
        "global_constants": 3
    },
    "methods_access": {
        "non_static": 82,
        "non_static_relative": 93.2,
        "static": 6,
        "static_relative": 6.8
    },
    "methods_visibility": {
        "public": 70,
        "public_relative": 79.5,
        "protected": 2,
        "protected_relative": 2.3,
        "private": 16,
        "private_relative": 18.2
    }
}

Longest files

Are you looking for top 10 longest files?

vendor/bin/lines measure --longest

 ----------------------------------------------------- ------------
  Longest files                                         Line count
 ----------------------------------------------------- ------------
  src/Measurements.php                                         320
  src/Console/OutputFormatter/TextOutputFormatter.php          136
  src/NodeVisitor/StructureNodeVisitor.php                     124
  src/Console/Command/MeasureCommand.php                        98
  src/Analyser.php                                              92
 ----------------------------------------------------- ------------

Scan package in /vendor

This tool measures your code, not the 3rd party libraries. It skips /vendor directory by default to avoid false positives. If you want to measure vendor files too, use --allow-vendor option:

 vendor/bin/lines measure vendor/rector/rector --allow-vendor

2. PHP Feature Counter

Two codebases using PHP 8.4 in composer.json, are not the same codebases. One has zero type param/return/property declarations, other has promoted properties. Reveal their real value by counting PHP feature they actually use.

vendor/bin/lines features src

For json output, just add --json:

vendor/bin/lines features src --json

This command:

  • scans your codebase,
  • count PHP feature being used from which PHP version,
  • gives you quick overview of how modern the codebase really is

For the text output, you'll get data like these:

PHP features
============


 ------------- ----------------------------------------------- ------------
  PHP version   PHP Feature                                     Count
 ------------- ----------------------------------------------- ------------
  7.0           Parameter types                                      2 793
  7.0           Return types                                         1 736
  7.0           Strict declares                                        492
  7.0           Space ship <=> operator                                  0
 ------------- ----------------------------------------------- ------------
  7.1           Nullable type (?type)                                  333
  7.1           Void return type                                       317
  7.1           Class constant visibility                              557
 ------------- ----------------------------------------------- ------------
  7.2           Object type                                             14
 ------------- ----------------------------------------------- ------------
  7.3           Coalesce ?? operator                                    69
 ------------- ----------------------------------------------- ------------
  7.4           Typed properties                                       156
  7.4           Arrow functions                                         38
  7.4           Coalesce assign (??=)                                    0
 ------------- ----------------------------------------------- ------------
  8.0           Named arguments                                         10
  8.0           Union types                                            147
  8.0           Match expression                                         1
  8.0           Nullsafe method call/property fetch                      0
  8.0           Attributes                                               0
  8.0           Throw expression                                       111
  8.0           Promoted properties                                    596
 ------------- ----------------------------------------------- ------------
  8.1           First-class callables                                    8
  8.1           Readonly property                                        3
  8.1           Intersection types                                       0
  8.1           Enums                                                    0
 ------------- ----------------------------------------------- ------------
  8.2           Readonly class                                         182
 ------------- ----------------------------------------------- ------------
  8.3           Typed class constants                                    0
 ------------- ----------------------------------------------- ------------
  8.4           Property hooks                                           0
 ------------- ----------------------------------------------- ------------

Or in a json format:

{
    "7.0": [
        {
            "name": "Parameter types",
            "count": 122
        },
        {
            "name": "Return types",
            "count": 143
        },
        {
            "name": "Strict declares",
            "count": 31
        },
        {
            "name": "Space ship <=> operator ",
            "count": 0
        },
        {
            "name": "Coalesce ?? operator",
            "count": 1
        }
    ],
    "7.1": [
        {
            "name": "Nullable type (?type)",
            "count": 5
        },
        {
            "name": "Void return type",
            "count": 48
        },
        {
            "name": "Class constant visibility",
            "count": 15
        }
    ],
    "7.2": [
        {
            "name": "Object type",
            "count": 3
        }
    ],
    "7.4": [
        {
            "name": "Typed properties",
            "count": 26
        },
        {
            "name": "Arrow functions",
            "count": 25
        },
        {
            "name": "Coalesce assign (??=)",
            "count": 0
        }
    ],
    "8.0": [
        {
            "name": "Named arguments",
            "count": 14
        },
        {
            "name": "Union types",
            "count": 5
        },
        {
            "name": "Match expression",
            "count": 0
        },
        {
            "name": "Nullsafe method call\/property fetch",
            "count": 0
        },
        {
            "name": "Attributes",
            "count": 0
        },
        {
            "name": "Throw expression",
            "count": 0
        },
        {
            "name": "Promoted properties",
            "count": 30
        }
    ],
    "8.1": [
        {
            "name": "First-class callables",
            "count": 0
        },
        {
            "name": "Readonly property",
            "count": 0
        },
        {
            "name": "Intersection types",
            "count": 0
        },
        {
            "name": "Enums",
            "count": 1
        }
    ],
    "8.2": [
        {
            "name": "Readonly class",
            "count": 6
        }
    ],
    "8.3": [
        {
            "name": "Typed class constants",
            "count": 9
        }
    ],
    "8.4": [
        {
            "name": "Property hooks",
            "count": 0
        }
    ]
}

That's it. Happy coding!

tomasvotruba/lines 适用场景与选型建议

tomasvotruba/lines 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 312.92k 次下载、GitHub Stars 达 351, 最近一次更新时间为 2023 年 07 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 tomasvotruba/lines 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tomasvotruba/lines 我们能提供哪些服务?
定制开发 / 二次开发

基于 tomasvotruba/lines 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 312.92k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 352
  • 点击次数: 20
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

  • Stars: 351
  • Watchers: 4
  • Forks: 11
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-31