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.
Installation:
composer require hiqdev/hidev-php
Add to your composer.json under extra:
"hidev": {
"plugins": ["hiqdev/hidev-php"]
}
First Use Case:
Run the default install goal to scaffold your project:
vendor/bin/hidev install
This generates:
.gitignoreLICENSE (via hidev-license)composer.json updates (via hidev-composer)Key Files to Review:
.hidev/config.php (main configuration)composer.json (updated with HiDev goals)php-cs-fixer.dist.php (if generated)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).Daily Development:
vendor/bin/php-cs-fixer fix --dry-run --diff
Integrate PHPStan into your workflow:
vendor/bin/hidev phpstan
vendor/bin/hidev phpunit
CI/CD Integration:
hidev-scrutinizer).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,
],
],
];
Generating Classes:
Use the gen command to create boilerplate classes:
vendor/bin/hidev gen Class --name=MyClass --namespace=App\Models
Laravel Compatibility:
composer.json scripts to integrate with Laravel’s tooling:
"scripts": {
"test": "phpunit",
"cs-fix": "php-cs-fixer fix",
"phpstan": "phpstan analyse src --level=5"
}
storage/, bootstrap/) from PHP-CS-Fixer:
'rules' => ['@PSR2', '--path-mode=intersection', '--exclude=storage/,bootstrap/'],
Artisan Integration: Create a custom Artisan command to trigger HiDev goals:
php artisan hidev:install
(Requires extending the hidev command class.)
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,
],
],
HiDev Dependency:
Class 'hidev\StartController' not found.composer global require hiqdev/hidev
hidev CLI directly if the package isn’t properly integrated.Outdated Configurations:
.travis.yml or .scrutinizer.yml manually to support newer PHP versions (e.g., 8.0+).# .travis.yml
php:
- 8.0
- 8.1
PHP-CS-Fixer Conflicts:
return, empty_return) may cause unexpected behavior if re-enabled.php-cs-fixer.dist.php and adjust rules incrementally:
return PhpCsFixerConfig::create()
->setRules([
'@PSR2' => true,
'return' => false, // Re-enable if needed
]);
PHPStan Level Mismatch:
'phpstan' => [
'level' => 3, // Less strict
],
Goal Execution Order:
license) may overwrite existing files silently.--dry-run to preview changes:
vendor/bin/hidev install --dry-run
Vendor Directory Exclusion:
vendor/ is not excluded.'rules' => ['@PSR2', '--exclude=vendor/'],
Verbose Output: Enable debug mode for HiDev commands:
vendor/bin/hidev install --verbose
Log Configuration:
Add logging to .hidev/config.php:
'components' => [
'log' => [
'class' => 'yii\log\FileTarget',
'logFile' => __DIR__ . '/hidev.log',
],
],
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
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',
],
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',
],
Pre/Post Actions:
Hook into HiDev’s lifecycle with onBeforeAction and onAfterAction:
'components' => [
'eventDispatcher' => [
'class' => 'yii\base\EventDispatcher',
'onBeforeAction' => ['App\Hidev\EventHandler', 'beforeAction'],
],
],
composer.json scripts may conflict with Laravel’s.composer.json:
"scripts": {
"post-install-cmd": [
"@php artisan hidev:install",
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"@php artisan package:discover --
How can I help you explore Laravel packages today?