Installation:
composer require --dev sstalle/php7cc
Add to composer.json under require-dev if not using global install.
First Run:
./vendor/bin/php7cc
Run in project root to scan all PHP files for PHP 7 compatibility issues.
Quick Check:
./vendor/bin/php7cc --format=json --output=php7cc-report.json src/
Generate a JSON report for CI/CD pipelines or programmatic use.
php7cc.phar (binary) – Main executable.src/Checker.php – Core logic for rule evaluation.src/Rules/ – Individual rule implementations (e.g., ArrayAccessRule, GeneratorRule).CI/CD Pipeline:
# Example GitHub Actions step
- name: PHP 7 Compatibility Check
run: ./vendor/bin/php7cc --fail-on=warning --format=checkstyle > php7cc-results.xml
Fail builds on warnings/errors, output Checkstyle format for IDE integration.
Pre-Commit Hook:
# .git/hooks/pre-commit
#!/bin/sh
./vendor/bin/php7cc --format=compact || exit 1
Block commits with PHP 7 incompatibilities.
Programmatic Use:
use Stalle\Php7cc\Checker;
$checker = new Checker();
$results = $checker->checkFiles(['src/Controller.php']);
foreach ($results as $file => $issues) {
foreach ($issues as $issue) {
echo "Line {$issue['line']}: {$issue['message']}\n";
}
}
Stalle\Php7cc\Rule\AbstractRule for project-specific checks (e.g., deprecated functions).False Positives:
ListRule may flag valid PHP 5.6 syntax (e.g., list($a, $b) = $array;).--ignore=ListRule or suppress specific lines with # @php7cc-ignore ListRule.Performance:
--path or parallelize checks in CI.Outdated Rules:
phpstan/extension-installer for modern checks.Verbose Output:
./vendor/bin/php7cc -v
Shows skipped files and rule details.
Custom Config:
# php7cc.ini
ignore = ListRule, GeneratorRule
fail_on = error
Place in project root to override defaults.
Add Custom Rules:
namespace App\Php7cc;
use Stalle\Php7cc\Rule\AbstractRule;
class MyCustomRule extends AbstractRule {
public function getName() { return 'MyCustomRule'; }
public function check($node) { /* ... */ }
}
Register via php7cc.phar --rules=App\Php7cc\MyCustomRule.
Override Default Rules:
Modify Stalle\Php7cc\Checker to exclude/include rules dynamically.
Format Output:
Extend Stalle\Php7cc\Formatter\AbstractFormatter for custom reporters (e.g., Slack alerts).
How can I help you explore Laravel packages today?