andersundsehr/grumphp-fractor-task
GrumPHP task for running Fractor (TYPO3 Fractor) in your Git hooks. Configure fractor.php path, file extensions, ignore patterns, cache clearing, and diff output to enforce automated refactoring checks on commit.
composer require --dev andersundsehr/grumphp-fractor-task
grumphp.yml:
grumphp:
tasks:
fractor: ~
extensions:
- Andersundsehr\GrumPHPFractorTask\ExtensionLoader
./vendor/bin/grumphp run
fractor.php config (if present in project root)..php files by default.declare(strict_types=1)Add this to grumphp.yml to validate strict typing in Laravel controllers:
tasks:
fractor:
triggered_by: ['php']
ignore_patterns: ['tests/*', 'vendor/*']
clear_cache: false # Cache results for faster local runs
Pre-Commit Hook
Add to .git/hooks/pre-commit:
#!/bin/sh
./vendor/bin/grumphp run --triggered-by=php
CI Pipeline (GitHub Actions Example)
- name: Run Fractor
run: ./vendor/bin/grumphp run --no-cache --strict
--no-cache in CI for consistent results.Custom Fractor Rules (fractor.php)
Override defaults for Laravel:
return [
'rules' => [
'strict_types' => [
'active' => true,
'level' => 'error',
'ignore_files' => ['app/Providers/AppServiceProvider.php'],
],
'class_naming' => [
'prefix' => 'App\\',
'suffix' => '',
'ignore' => ['Migrations', 'Console'],
],
],
];
Exclude Laravel Artifacts
tasks:
fractor:
ignore_patterns:
- 'bootstrap/cache/*'
- 'storage/*'
- 'vendor/*'
- 'tests/Feature/*'
Combine with other GrumPHP tasks for a full Laravel workflow:
tasks:
phpcs_fixer: ~
fractor: ~
phpstan: ~
phpunit: ~
phpcs_fixer (fix formatting first) but before phpstan (catch structural issues early).Fractor’s TYPO3 Focus
AppServiceProvider).ignore_patterns or override rules in fractor.php.Cache Invalidation
fractor.php changes.--no-cache locally after config updates:
./vendor/bin/grumphp run --no-cache
Performance in Large Repos
triggered_by to critical paths:
triggered_by: ['app/Http/Controllers/', 'app/Models/']
Verbose Output Enable diffs for debugging:
tasks:
fractor:
no_diffs: false
Isolate Issues Run Fractor on a single file:
./vendor/bin/grumphp run --files=app/Http/Controllers/UserController.php
Check Exit Codes
Fractor returns 1 on failures. Use in CI:
- name: Fractor Check
run: |
if ! ./vendor/bin/grumphp run --no-cache; then
echo "Fractor failed!"
exit 1
fi
Custom Rules
Extend Fractor’s ruleset by creating a custom config file (e.g., config/fractor-laravel.php) and reference it:
tasks:
fractor:
config: "config/fractor-laravel.php"
Dynamic Ignore Patterns Use environment variables for flexible ignores:
tasks:
fractor:
ignore_patterns:
- "${IGNORE_PATTERN:-tests/*}"
Parallel Execution Speed up runs with GrumPHP’s parallel flag:
./vendor/bin/grumphp run --parallel
__get() magic methods. Add to ignore_patterns if needed.class_naming may conflict with Laravel’s bind() conventions. Override in fractor.php:
'class_naming' => [
'ignore' => ['app/Providers/RepositoryServiceProvider.php'],
],
How can I help you explore Laravel packages today?