Static Analysis
Phexium uses static analysis tools to maintain code quality and enforce modern PHP practices.
Rector
Rector automates code refactoring and modernization.
Configuration
Rector is configured in rector.php:
return RectorConfig::configure()
->withPaths([__DIR__.'/app', __DIR__.'/src', __DIR__.'/tests'])
->withPhpSets(php84: true)
->withPreparedSets(
deadCode: true,
codeQuality: true,
typeDeclarations: true,
earlyReturn: true,
);
Common Transformations
Constructor Property Promotion:
// Before
class Book {
private string $title;
public function __construct(string $title) {
$this->title = $title;
}
}
// After
class Book {
public function __construct(private string $title) {}
}
Early Return:
// Before
if ($condition) {
return $this->process();
}
return null;
// After
if (!$condition) {
return null;
}
return $this->process();
Safe Usage
- Always review changes before committing
- Run tests after applying transformations
- Use version control to revert unwanted changes
SonarQube
SonarQube provides comprehensive static analysis including code smells, bugs, and vulnerabilities. Configuration is in sonar-project.properties.