定制 niels-de-blaauw/php-doc-check 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

niels-de-blaauw/php-doc-check

Composer 安装命令:

composer require niels-de-blaauw/php-doc-check

包简介

Command line tool that identifies code that needs documentation.

README 文档

README

Latest Stable Version Build Status License

PHP Doc Check is an automated command line tool to determine which functions and methods could use some more documentation.

By default this script:

  • Emits a warning if there is no docblock for non trivial functions (score > 4)
  • Emits an error if there is no docblock for complex functions (score > 6)

You can gradually improve documenation on projects by starting with relatively high limits and slowly moving these limits down.

Metrics

Installation

Composer

For now you have to install the beta version.

composer require --dev niels-de-blaauw/php-doc-check:^0.2.0@dev

Phive

phive install php-doc-check

Usage

$vendor/bin/php-doc-check -?
Usage: vendor/bin/php-doc-check [options] <directory> [<directory>...]

Options:
  -x, --exclude <arg>                       Directories to exclude, without
                                            slash
  -f, --format <arg>                        Output format [text, json]
                                            [default: text]
  -o, --reportFile <arg>                    Send report output to a file
  -m, --metric <arg>                        Metric to use for determining
                                            complexity
                                            [metrics.complexity.cognitive,
                                            metrics.complexity.cyclomatic,
                                            metrics.deprecated.category,
                                            metrics.deprecated.subpackage,
                                            metrics.complexity.length]
                                            [default:
                                            metrics.complexity.cognitive]
  -w, --complexity-warning-threshold <arg>  Cyclomatic complexity score which
                                            is the lower bound for a warning
                                            [default: 4]
  -e, --complexity-error-threshold <arg>    Cyclomatic complexity score which
                                            is the lower bound for an error
                                            [default: 6]
  -$, --file-extension <arg>                Valid file extensions to scan
                                            [default: php]
  -g, --grouping-method <arg>               Allows different grouping of the
                                            results list [file, none, metric,
                                            severity, fileline] [default: file]
  -s, --sorting-method <arg>                Sorting for the results. Natural
                                            sorts by name for groups and line
                                            for findings. Value uses the
                                            cumulative group score, and finding
                                            score as sorting value. [natural,
                                            value] [default: natural]
  -i, --ignore-violations-on-exit           Will exit with a zero code, even if
                                            any violations are found
  -a, --ignore-anonymous-functions          Skip checks on anonymous functions
  -?, --help                                Show this help and quit
  -q, --quiet                               Don't show any output

Example first use: vendor/bin/php-doc-check --exclude vendor ./

Examples

This is fine without docblocks (trivial method)

public function get_title() : string{
    return strtoupper($this->title);
}

This could use some explanation

/**
 * Limits the length of the title to a normal sentence, because older titles
 * tend to be longer then we can currently show.
 */
public function get_title() : string{
    if(strlen($this->title) > 20 ){
        if(strpos($this->title,'.') !== false && strpos($this->title,'.') < 20){
            [$title] = explode('.', $this->title, 2);
        }else{
            $title = substr($this->title, 0, 17) . '...';
        }
    }else{
        $title = $this->title;
    }
    return strtoupper($title);
}

FAQ

Q: Why dont you want if there is no comment at all, regardless of complexity?

A: You can set this software to warn for all functions that are undocumented by setting --complexity-error-threshold 1. However, if you want to force documentation, you probably want to look into a tool like php CodeSniffer in combination with documentation standards.

Q: Why isn't there a warning/error about complex functions and refactoring, regardless if they have a DocBlock?

A: You should refactor very complex functions. However, adding DocBlocks for complex function is often easier and safer. This tool only checks the availability of this type of documentation. Other tools, like php Mess Detector, can help you limit complexity.

Issues

Issues are in the GitHub tracker: https://github.com/NielsdeBlaauw/php-doc-check/issues

niels-de-blaauw/php-doc-check 适用场景与选型建议

niels-de-blaauw/php-doc-check 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 242.11k 次下载、GitHub Stars 达 43, 最近一次更新时间为 2019 年 01 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 niels-de-blaauw/php-doc-check 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 242.11k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 43
  • 点击次数: 19
  • 依赖项目数: 4
  • 推荐数: 1

GitHub 信息

  • Stars: 43
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-17