定制 kwadwokyeremeh/laravel-package-ide-helper 二次开发

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

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

kwadwokyeremeh/laravel-package-ide-helper

Composer 安装命令:

composer require kwadwokyeremeh/laravel-package-ide-helper

包简介

Standalone IDE Helper Generator for Laravel Packages - No Laravel Required

README 文档

README

A standalone IDE helper generator and linter for Laravel packages. Unlike other IDE helper tools, this works without requiring Laravel application or artisan command access - perfect for package development!

🎯 Why This Package?

When developing Laravel packages, you don't have access to php artisan ide-helper:generate. This tool solves that by:

  • No Laravel required - Works on any PHP codebase
  • Static analysis - Analyzes code without bootstrapping Laravel
  • Package-aware - Understands Laravel package structure
  • IDE agnostic - Works with VS Code, PHPStorm, Vim, etc.
  • Zero configuration - Auto-detects namespace, vendor, and structure
  • Built-in linter - Catches common issues and enforces best practices

📦 Installation

As a Development Dependency

composer require --dev kwadwokyeremeh/laravel-package-ide-helper

Globally

composer global require kwadwokyeremeh/laravel-package-ide-helper

🚀 Usage

Generate IDE Helpers

Run from your package root:

vendor/bin/generate-ide-helper generate .

This will:

  1. Scan your package for Models, Facades, Commands, etc.
  2. Generate IDE helper files in .idea-ide-helper/
  3. Create PHPDoc stubs for better autocompletion

Advanced Usage

# Specify output directory
vendor/bin/generate-ide-helper generate . --output ./ide-helpers

# Use custom config
vendor/bin/generate-ide-helper generate . --config my-config.php

# Generate only models
vendor/bin/generate-ide-helper generate . --models true --facades false --commands false

# Override namespace
vendor/bin/generate-ide-helper generate . --namespace "MyPackage\\Namespace"

# Specify vendor name
vendor/bin/generate-ide-helper generate . --vendor "my-vendor"

Command Options

generate <path> [options]

Arguments:
  path                  Path to the Laravel package directory

Options:
  --output, -o          Output directory for IDE helper files (default: .idea-ide-helper)
  --config, -c          Path to configuration file
  --models, -M          Generate model helpers (default: true)
  --facades, -F         Generate facade helpers (default: true)
  --commands, -C        Generate command helpers (default: true)
  --events, -E          Generate event/helpers (default: false)
  --providers, -P       Generate service provider helpers (default: true)
  --namespace, -N       Package namespace (auto-detected if not provided)
  --vendor-name         Vendor name (auto-detected if not provided)
  --inline, -i          Inject PHPDocs directly into model files (recommended!)
  --backup, -b          Create backup before modifying files (use with --inline)
  --help, -h            Show help

📝 Inline PHPDoc Injection (Recommended)

The --inline option injects comprehensive PHPDoc blocks directly into your model files!

Usage:

# Inject PHPDocs into models
vendor/bin/generate-ide-helper generate . --inline

# With backup
vendor/bin/generate-ide-helper generate . --inline --backup

Example Output:

/**
 * App\Models\User
 *
 * @table users
 *
 * @property int $id (auto-increment)
 * @property string $name
 * @property \Illuminate\Support\Carbon|string|null $email_verified_at
 * @property string|null $settings - User preferences
 * @property float $balance (default: 0.00)
 *
 * @method \Illuminate\Database\Eloquent\Relations\HasMany|Post[] posts()
 * @method static \Illuminate\Database\Eloquent\Builder|User query()
 */
class User extends Model { ... }

🔍 Linter

The package includes a powerful linter that checks your Laravel package for common issues, best practices, and code quality problems.

Basic Linting

vendor/bin/generate-ide-helper lint .

Advanced Linting

# Output as JSON
vendor/bin/generate-ide-helper lint . --format json

# Save report to file
vendor/bin/generate-ide-helper lint . --format file --output lint-report.json

# Only show errors and warnings
vendor/bin/generate-ide-helper lint . --severity warning

# Run only specific checks
vendor/bin/generate-ide-helper lint . --only models --only commands

# Exclude specific checks
vendor/bin/generate-ide-helper lint . --exclude naming --exclude types

# Fail on warnings instead of errors
vendor/bin/generate-ide-helper lint . --fail-on warning

# Use custom config
vendor/bin/generate-ide-helper lint . --config lint-config.php

Lint Command Options

lint <path> [options]

Arguments:
  path                  Path to the Laravel package directory

Options:
  --config, -c          Path to configuration file
  --format, -f          Output format: console, json, file (default: console)
  --output, -o          Output file path (for file format)
  --severity, -s        Minimum severity: error, warning, info, hint (default: hint)
  --only                Run only specific checks (e.g., models, commands)
  --exclude             Exclude specific checks
  --fail-on             Exit with error on: error, warning (default: error)

Available Lint Checks

Check Description
general PHP tags, namespaces, strict types, trailing whitespace
models Fillable/guarded, casts, relationships, table names
facades Accessor methods, proper facade structure
commands Signatures, descriptions, handle methods, return types
providers Register/boot methods, parent calls, config publishing
naming File names, class names, naming conventions
types Return types, parameter types, type hints
best_practices Security issues, debug functions, hardcoded secrets

Example Lint Output

┌─────────────────────────────────────────────────────────────┐
│                    Laravel Package Linter                    │
└─────────────────────────────────────────────────────────────┘

Scanning Package
================

─────────────────────────────────────────────────────────────
Lint Results
─────────────────────────────────────────────────────────────

 ❌  Errors (2)

 src/Models/User.php:15 - Model doesn't define $fillable or $guarded. 
    This may allow mass assignment vulnerabilities.
    💡 Suggestion: Define protected $fillable = [...] or protected $guarded = ['*'];

 src/Commands/MyCommand.php:1 - Command is missing $signature property.
    💡 Suggestion: Add: protected $signature = 'your:command {argument?} {--option?}';

 ⚠️  Warnings (3)

 src/Models/Post.php:1 - Consider defining $casts property for automatic type conversion.

─────────────────────────────────────────────────────────────
Summary
─────────────────────────────────────────────────────────────

 ┌─────────────────┬───────┐
 │ Metric          │ Count │
 ├─────────────────┼───────┤
 │ Files Scanned   │ 12    │
 │ Total Issues    │ 5     │
 │ ❌ Errors       │ 2     │
 │ ⚠️  Warnings    │ 3     │
 │ ℹ️  Info         │ 0     │
 │ 💡 Hints        │ 0     │
 └─────────────────┴───────┘

 ❌ Found 2 error(s). Please fix them before proceeding.

Lint Configuration

Create a custom config file for advanced linting:

<?php
// lint-config.php

return [
    'source_dirs' => ['src', 'lib'],
    
    'exclude' => ['vendor', 'tests', 'node_modules'],
    
    'checks' => [
        'general' => true,
        'models' => true,
        'facades' => true,
        'commands' => true,
        'providers' => true,
        'naming' => true,
        'types' => true,
        'best_practices' => true,
    ],
];

Then use it with:

vendor/bin/generate-ide-helper lint . --config lint-config.php

📁 Generated Files

After running the generator, you'll get:

.idea-ide-helper/
├── _ide_helper.php              # Main entry point (includes all files)
├── _ide_helper_models.php       # Model PHPDoc stubs
├── _ide_helper_facades.php      # Facade PHPDoc stubs
├── _ide_helper_commands.php     # Command PHPDoc stubs
├── _ide_helper_providers.php    # Service provider PHPDoc stubs
└── _ide_helper_events.php       # Event PHPDoc stubs (if enabled)

🔧 IDE Configuration

VS Code

Add to .vscode/settings.json:

{
    "php.suggestPaths": [
        ".idea-ide-helper/_ide_helper.php"
    ],
    "intelephense.files.include": [
        ".idea-ide-helper/**/*.php"
    ]
}

PHPStorm

  1. Go to Settings > Languages & Frameworks > PHP
  2. Add .idea-ide-helper/ to the Include paths
  3. The IDE will automatically recognize the helper files

Vim (with ALE or CoC)

Add to your .vimrc or .config/nvim/init.vim:

let g:ale_php_namespace_paths = ['.idea-ide-helper']

📝 Configuration File

Create a custom config file for advanced usage:

vendor/bin/generate-ide-helper generate . --config ide-helper-config.php

Example ide-helper-config.php:

<?php

return [
    'source_dirs' => ['src', 'lib'],
    
    'output' => [
        'directory' => '.idea-ide-helper',
        'format' => 'php',
    ],
    
    'generate' => [
        'models' => true,
        'facades' => true,
        'commands' => true,
        'providers' => true,
        'events' => false,
    ],
    
    'models' => [
        'include_magic_properties' => true,
        'include_relationships' => true,
        'include_scopes' => true,
    ],
    
    'exclude' => [
        'vendor',
        'tests',
        'node_modules',
    ],
];

🎨 Example Output

For Models

<?php

namespace YourPackage\Models {

    /**
     * YourPackage\Models\User
     *
     * @table users
     * @property int $id
     * @property string $name
     * @property string $email
     * @property bool $is_active
     * @property \Illuminate\Support\Carbon|string $created_at
     * @property \Illuminate\Support\Carbon|string $updated_at
     * @method \Illuminate\Database\Eloquent\Relations\HasMany|\Illuminate\Database\Eloquent\Collection|Post[] posts()
     * @method static \Illuminate\Database\Eloquent\Builder|User query()
     * @method static \Illuminate\Database\Eloquent\Builder|User where($column, $operator = null, $value = null, $boolean = 'and')
     * @method static \Illuminate\Database\Eloquent\Builder|User create(array $attributes = [])
     */
    class User extends \Illuminate\Database\Eloquent\Model {}

}

For Facades

<?php

namespace YourPackage\Facades {

    /**
     * Facade: YourPackage\Facades\MyService
     * @accessor my-service
     */
    class MyService extends \Illuminate\Support\Facades\Facade {}

}

🔄 Continuous Integration

Add to your CI/CD pipeline to keep IDE helpers up-to-date:

# GitHub Actions Example
- name: Generate IDE Helpers
  run: vendor/bin/generate-ide-helper generate .
  
- name: Check for changes
  run: git diff --exit-code .idea-ide-helper/

📋 What Gets Analyzed?

Component What's Detected
Models Properties, fillable, casts, relationships, table name
Facades Class name, accessor, namespace
Commands Signature, description, namespace
Providers Service provider classes, namespaces
Events Event classes, namespaces
Middlewares Middleware classes
Jobs Job classes (ShouldQueue)
Listeners Event listener classes

🛠️ Requirements

  • PHP 8.1 or higher
  • No Laravel installation required!

🤝 Contributing

Contributions are welcome! Please read our Contributing Guide for details.

📄 License

The MIT License (MIT). Please see License File for more information.

🙏 Credits

Created by Kyeremeh

Inspired by the need for better IDE support in Laravel package development.

🐛 Issues & Support

If you encounter any issues or have questions, please open an issue.

Happy Package Developing! 🎉

kwadwokyeremeh/laravel-package-ide-helper 适用场景与选型建议

kwadwokyeremeh/laravel-package-ide-helper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 04 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 kwadwokyeremeh/laravel-package-ide-helper 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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