Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Hidev Php Laravel Package

hiqdev/hidev-php

HiDev plugin for PHP projects providing standard project scaffolding and automation: generates/maintains .gitignore, LICENSE, README, CHANGELOG, composer.json, and integrates PHP-CS-Fixer, PHPStan, PHPUnit, Travis CI, and Scrutinizer configs.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require hiqdev/hidev-php
    

    Add to your composer.json under extra:

    "hidev": {
        "plugins": ["hiqdev/hidev-php"]
    }
    
  2. First Use Case: Run the default install goal to scaffold your project:

    vendor/bin/hidev install
    

    This generates:

    • .gitignore
    • LICENSE (via hidev-license)
    • composer.json updates (via hidev-composer)
    • Basic PHP-CS-Fixer and PHPUnit configs.
  3. Key Files to Review:

    • .hidev/config.php (main configuration)
    • composer.json (updated with HiDev goals)
    • php-cs-fixer.dist.php (if generated)

Implementation Patterns

Core Workflows

  1. Project Scaffolding: Use hidev install to bootstrap a new project with:

    vendor/bin/hidev install --goal=all
    

    Goals include:

    • gitignore: Generates .gitignore for PHP projects.
    • license: Adds a LICENSE file (default: BSD-3-Clause).
    • composer: Updates composer.json with HiDev-specific configs.
    • php-cs-fixer: Configures PSR-2 coding standards.
    • phpunit: Sets up PHPUnit for testing.
    • travis: Adds Travis CI configuration.
    • phpstan: Enables static analysis (added in v0.6.2).
  2. Daily Development:

    • Code Quality: Run PHP-CS-Fixer interactively:
      vendor/bin/php-cs-fixer fix --dry-run --diff
      
      Integrate PHPStan into your workflow:
      vendor/bin/hidev phpstan
      
    • Testing: Execute PHPUnit tests with:
      vendor/bin/hidev phpunit
      
  3. CI/CD Integration:

    • Travis CI is preconfigured to run:
      • PHPUnit tests.
      • PHP-CS-Fixer checks.
      • PHPStan analysis.
    • Scrutinizer is set up for coverage reporting (via hidev-scrutinizer).
  4. Customization: Extend the default configuration in .hidev/config.php:

    return [
        'components' => [
            'php-cs-fixer' => [
                'class' => 'hidev\phpcs\PhpCsFixer',
                'config' => __DIR__ . '/php-cs-fixer.dist.php',
                'rules' => ['@PSR2', '--path-mode=intersection'],
            ],
            'phpstan' => [
                'class' => 'hidev\phpstan\PhpStan',
                'config' => __DIR__ . '/phpstan.neon',
                'level' => 5,
            ],
        ],
    ];
    
  5. Generating Classes: Use the gen command to create boilerplate classes:

    vendor/bin/hidev gen Class --name=MyClass --namespace=App\Models
    

Laravel-Specific Tips

  1. Laravel Compatibility:

    • Override the default composer.json scripts to integrate with Laravel’s tooling:
      "scripts": {
          "test": "phpunit",
          "cs-fix": "php-cs-fixer fix",
          "phpstan": "phpstan analyse src --level=5"
      }
      
    • Exclude Laravel-specific directories (e.g., storage/, bootstrap/) from PHP-CS-Fixer:
      'rules' => ['@PSR2', '--path-mode=intersection', '--exclude=storage/,bootstrap/'],
      
  2. Artisan Integration: Create a custom Artisan command to trigger HiDev goals:

    php artisan hidev:install
    

    (Requires extending the hidev command class.)

  3. Environment-Specific Configs: Use Laravel’s environment files to conditionally enable HiDev goals:

    // .hidev/config.php
    'goals' => [
        'install' => [
            'gitignore' => true,
            'license' => env('APP_ENV') !== 'local',
            'php-cs-fixer' => true,
        ],
    ],
    

Gotchas and Tips

Pitfalls

  1. HiDev Dependency:

    • Error: Class 'hidev\StartController' not found.
    • Fix: Ensure HiDev is installed globally or as a project dependency:
      composer global require hiqdev/hidev
      
    • Workaround: Use the hidev CLI directly if the package isn’t properly integrated.
  2. Outdated Configurations:

    • Issue: Travis CI or Scrutinizer configs may reference deprecated PHP versions (e.g., PHP 5.6).
    • Fix: Update .travis.yml or .scrutinizer.yml manually to support newer PHP versions (e.g., 8.0+).
    • Example:
      # .travis.yml
      php:
        - 8.0
        - 8.1
      
  3. PHP-CS-Fixer Conflicts:

    • Problem: Disabled fixers (e.g., return, empty_return) may cause unexpected behavior if re-enabled.
    • Tip: Review php-cs-fixer.dist.php and adjust rules incrementally:
      return PhpCsFixerConfig::create()
          ->setRules([
              '@PSR2' => true,
              'return' => false, // Re-enable if needed
          ]);
      
  4. PHPStan Level Mismatch:

    • Warning: Default PHPStan level is 5 (strict). Lower it for legacy codebases:
      'phpstan' => [
          'level' => 3, // Less strict
      ],
      
  5. Goal Execution Order:

    • Gotcha: Some goals (e.g., license) may overwrite existing files silently.
    • Tip: Use --dry-run to preview changes:
      vendor/bin/hidev install --dry-run
      
  6. Vendor Directory Exclusion:

    • Issue: PHP-CS-Fixer may fail if vendor/ is not excluded.
    • Fix: Ensure the config includes:
      'rules' => ['@PSR2', '--exclude=vendor/'],
      

Debugging Tips

  1. Verbose Output: Enable debug mode for HiDev commands:

    vendor/bin/hidev install --verbose
    
  2. Log Configuration: Add logging to .hidev/config.php:

    'components' => [
        'log' => [
            'class' => 'yii\log\FileTarget',
            'logFile' => __DIR__ . '/hidev.log',
        ],
    ],
    
  3. Isolated Testing: Test HiDev goals in a temporary directory:

    mkdir /tmp/hidev-test && cd /tmp/hidev-test
    composer init
    composer require hiqdev/hidev-php
    vendor/bin/hidev install
    

Extension Points

  1. Custom Goals: Extend HiDev by creating a custom plugin. Example:

    // CustomPlugin.php
    namespace App\Hidev;
    
    use hidev\BasePlugin;
    
    class CustomPlugin extends BasePlugin {
        public function init() {
            $this->goal('custom-goal')->action(function() {
                // Custom logic here
            });
        }
    }
    

    Register it in .hidev/config.php:

    'plugins' => [
        'App\Hidev\CustomPlugin',
    ],
    
  2. Dynamic Configs: Load configurations dynamically based on environment variables:

    'php-cs-fixer' => [
        'config' => env('HIDEV_PHP_CS_FIXER_CONFIG') ?: __DIR__ . '/php-cs-fixer.dist.php',
    ],
    
  3. Pre/Post Actions: Hook into HiDev’s lifecycle with onBeforeAction and onAfterAction:

    'components' => [
        'eventDispatcher' => [
            'class' => 'yii\base\EventDispatcher',
            'onBeforeAction' => ['App\Hidev\EventHandler', 'beforeAction'],
        ],
    ],
    

Laravel-Specific Gotchas

  1. Service Provider Conflicts:
    • Issue: HiDev’s composer.json scripts may conflict with Laravel’s.
    • Fix: Merge scripts in composer.json:
      "scripts": {
          "post-install-cmd": [
              "@php artisan hidev:install",
              "Illuminate\\Foundation\\ComposerScripts::postInstall",
              "@php artisan package:discover --
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky