定制 laravel-analyzer/cli 二次开发

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

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

laravel-analyzer/cli

Composer 安装命令:

composer require laravel-analyzer/cli

包简介

Static analysis CLI and MCP server for Laravel projects — zero dependencies, pure PHP 8.2+

README 文档

README

A command-line tool for analyzing the quality and security of Laravel projects. Zero external dependencies — pure PHP only.

📦 Installation

Option A — Direct use (no composer install required)

git clone https://github.com/your-user/laravel-analyzer
cd laravel-analyzer
chmod +x bin/laravel-analyze
php bin/laravel-analyze /path/to/your-laravel-project

Option B — Global via Composer

composer global require laravel-analyzer/cli
laravel-analyze /path/to/your-project

🚀 Usage

# Analyze the current directory
laravel-analyze .

# Analyze a specific path
laravel-analyze /var/www/my-project

# Run only specific modules
laravel-analyze . --only=security,owasp

# Export HTML report
laravel-analyze . --format=html --output=report.html

# Export JSON for CI/CD
laravel-analyze . --format=json --output=analysis.json

# Export Markdown (for GitHub/GitLab)
laravel-analyze . --format=markdown --output=ANALYSIS.md

# Set a minimum quality threshold
laravel-analyze . --threshold=75

# Disable colors (for logs/CI)
laravel-analyze . --no-color

📊 Analysis Modules

🔗 Coupling & Cohesion (coupling)

Detects violations of the Single Responsibility Principle (SRP).

Metric Description
Average coupling Number of dependencies per class
God Classes Classes with > 20 methods or > 500 lines
Long methods Methods with > 50 lines
Estimated cohesion How related the class responsibilities are

How to improve?

  • Break God Classes into specific services
  • Use dependency injection instead of new ClassName()
  • Define interfaces for each dependency

🧪 Test Coverage (testing)

Evaluates the quality and coverage of the test suite.

Metric Description
Unit tests Files in tests/Unit/
Feature tests Files in tests/Feature/
Test/code ratio % of source files with associated tests
Line coverage From clover.xml (if present)

To generate a coverage report:

php artisan test --coverage-clover=coverage.xml
laravel-analyze .  # Detects coverage.xml automatically

💸 Technical Debt (debt)

Identifies indicators of accumulated technical debt.

Indicator Severity
FIXME HIGH
HACK / XXX MEDIUM
TODO LOW
$guarded = [] CRITICAL
Model::create($request->all()) CRITICAL
Dependencies with wildcard version * HIGH
Large commented-out code blocks MEDIUM

🧮 Refactoring Complexity (complexity)

Analyzes the Cyclomatic Complexity (CC) of each method.

CC Risk Description
1–5 Low Simple, easy to test
6–10 Medium Moderate, testable
11–20 High Hard to test
> 20 Critical Practically untestable

Formula: CC = 1 + (if + for + foreach + while + case + catch + && + \|\|)

🔒 Laravel Security (security)

Detects vulnerabilities specific to the Laravel ecosystem.

Vulnerability OWASP Dangerous example
SQL Injection A03 DB::select("SELECT * WHERE id=" . $id)
Mass Assignment A01 Model::create($request->all())
XSS A03 {!! $userInput !!}
Command Injection A03 shell_exec("ls " . $path)
Weak Hashing A02 md5($password)
Open Redirect A01 redirect($request->get('url'))
Debug in prod A05 APP_DEBUG=true + APP_ENV=production

🛡️ OWASP Top 10 (owasp)

Checks the project against the OWASP Top 10 standard (2021).

Code Category What it checks
A01 Broken Access Control Policies, IDOR, protected routes
A02 Cryptographic Failures MD5/SHA1, hardcoded secrets, HTTPS
A03 Injection SQL, Command, Object injection
A04 Insecure Design Rate limiting, validation on store/update
A05 Security Misconfiguration APP_DEBUG, SameSite cookies, CORS
A06 Vulnerable Components Dependency versions, composer.lock
A07 Auth Failures Session fixation, MFA, regeneration
A08 Integrity Failures CI/CD, unserialize(), secure pipelines
A09 Logging Failures Security events logged
A10 SSRF HTTP requests with user-supplied URLs

📋 Output Formats

Console (default)

Colorized terminal view with progress bars.

JSON

{
  "generated_at": "2025-03-21 10:00:00",
  "project": "my-laravel-app",
  "global_score": 72.5,
  "grade": "B",
  "analyses": {
    "coupling": { "score": 78.2, "risk": "MEDIUM", ... },
    "owasp": { "score": 65.0, "risk": "MEDIUM", ... }
  }
}

HTML

Full visual report with tables, progress bars, and OWASP breakdown.

Markdown

Compatible with GitHub/GitLab. Ideal for PRs or documentation wikis.

🔄 CI/CD Integration

GitHub Actions

name: Laravel Quality Check
on: [push, pull_request]

jobs:
  analyze:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.2'

      - name: Run Laravel Analyzer
        run: php bin/laravel-analyze . --format=json --output=analysis.json --no-color

      - name: Check quality threshold
        run: |
          SCORE=$(python3 -c "import json; d=json.load(open('analysis.json')); print(d['global_score'])")
          if python3 -c "exit(0 if $SCORE >= 60 else 1)"; then
            echo "Quality score: $SCORE/100 — OK"
          else
            echo "Quality score ($SCORE) below threshold (60)"; exit 1
          fi

      - name: Upload report
        uses: actions/upload-artifact@v3
        with:
          name: laravel-analysis
          path: analysis.json

GitLab CI

laravel-analysis:
  stage: test
  script:
    - php bin/laravel-analyze . --format=json --output=analysis.json --no-color --threshold=65
  artifacts:
    paths:
      - analysis.json

🛠️ Complementary Tools

Tool Installation Purpose
Larastan/PHPStan composer require --dev nunomaduro/larastan Advanced static analysis
Laravel Pint Included in Laravel 9+ Code formatting
Enlightn composer require --dev enlightn/enlightn Security audit
PHP Insights composer require nunomaduro/phpinsights Quality metrics
PHPMD composer require --dev phpmd/phpmd Code smell detection

📈 Score Interpretation

Score Grade Meaning
90–100 A+ Excellent quality
80–89 A Very good quality
70–79 B Good quality, minor improvements needed
60–69 C Acceptable quality, work needed
50–59 D Low quality, urgent refactoring required
< 50 F Critical quality, high risk

📝 License

MIT License — Free for commercial and personal use.

laravel-analyzer/cli 适用场景与选型建议

laravel-analyzer/cli 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「security」 「cli」 「laravel」 「static-analysis」 「owasp」 「mcp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 laravel-analyzer/cli 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 49
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-21