sjparkinson/static-review 问题修复 & 功能扩展

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

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

sjparkinson/static-review

最新稳定版本:5.2.2

Composer 安装命令:

composer require sjparkinson/static-review

包简介

An extendable framework for version control hooks.

README 文档

README

This package is abandoned ????.

See GrumPHP for a maintained alternative.

An extendable framework for version control hooks.

StaticReview Success Demo

Usage

For a composer managed project you can simply run the following ...

$ composer require sjparkinson/static-review

Hooks can then be installed like so ...

$ vendor/bin/static-review.php hook:install vendor/sjparkinson/static-review/hooks/example-pre-commit.php .git/hooks/pre-commit

Otherwise, if you don't use composer ...

$ git clone https://github.com/sjparkinson/static-review.git $ cd static-review/ $ composer install --no-dev --optimize-autoloader $ bin/static-review.php hook:install hooks/example-pre-commit.php ~/.../.git/hooks/pre-commit

Global Installation and Usage

The hooks can also be used for any project if you install static-review globally:

$ composer g require sjparkinson/static-review

Then, just install the hooks as you would normally but reference the global installation path:

$ static-review.php hook:install ~/.composer/vendor/sjparkinson/static-review/hooks/static-review-commit-msg.php .git/hooks/commit-msg

This assumes you have set up global composer paths.

Example Hooks

Static Review can be used for both files and commit message review. Below are basic hooks for each.

For Files

#!/usr/bin/env php <?php include __DIR__ . '/../../../autoload.php'; // Reference the required classes. use StaticReview\StaticReview; use StaticReview\Review\General\LineEndingsReview; [...] $reporter = new Reporter(); $review = new StaticReview($reporter); // Add any reviews to the StaticReview instance, supports a fluent interface. $review->addReview(new LineEndingsReview()); $git = new GitVersionControl(); // Review the staged files. $review->files($git->getStagedFiles()); // Check if any issues were found. // Exit with a non-zero status to block the commit. ($reporter->hasIssues()) ? exit(1) : exit(0);

For Commit Messages

#!/usr/bin/env php <?php include __DIR__ . '/../../../autoload.php'; // Reference the required classes. use StaticReview\StaticReview; use StaticReview\Review\Message\BodyLineLengthReview; [...] $reporter = new Reporter(); $review = new StaticReview($reporter); // Add any reviews to the StaticReview instance, supports a fluent interface. $review->addReview(new BodyLineLengthReview()); $git = new GitVersionControl(); // Review the current commit message. // The hook is passed the file holding the commit message as the first argument. $review->message($git->getCommitMessage($argv[1])); // Check if any issues were found. // Exit with a non-zero status to block the commit. ($reporter->hasIssues()) ? exit(1) : exit(0);

Example Review For Files

class NoCommitTagReview extends AbstractFileReview { // Review any text based file. public function canReviewFile(FileInterface $file) { $mime = $file->getMimeType(); // check to see if the mime-type starts with 'text' return (substr($mime, 0, 4) === 'text'); } // Checks if the file contains `NOCOMMIT`. public function review(ReporterInterface $reporter, ReviewableInterface $file) { $cmd = sprintf('grep --fixed-strings --ignore-case --quiet "NOCOMMIT" %s', $file->getFullPath()); $process = $this->getProcess($cmd); $process->run(); if ($process->isSuccessful()) { $message = 'A NOCOMMIT tag was found'; $reporter->error($message, $this, $file); } } }

Example Review For Messages

class WorkInProgressReview extends AbstractMessageReview { // Check if the commit message contains "wip" public function review(ReporterInterface $reporter, ReviewableInterface $commit) { $fulltext = $commit->getSubject() . PHP_EOL . $commit->getBody(); if (preg_match('/\bwip\b/i', $fulltext)) { $message = 'Do not commit WIP to shared branches'; $reporter->error($message, $this, $commit); } } }

Unit Tests

See vagrantup.com and phpunit.de.

$ git clone https://github.com/sjparkinson/static-review.git $ cd static-review/ $ vagrant up $ vagrant ssh ... $ cd /srv $ composer update $ composer test

Licence

The content of this library is released under the MIT License by Samuel Parkinson.

sjparkinson/static-review 适用场景与选型建议

sjparkinson/static-review 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.23M 次下载、GitHub Stars 达 326, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 sjparkinson/static-review 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 3.23M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 328
  • 点击次数: 25
  • 依赖项目数: 33
  • 推荐数: 0

GitHub 信息

  • Stars: 326
  • Watchers: 15
  • Forks: 26
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04