Skip to content

Static Analysis

Phexium uses static analysis tools to maintain code quality and enforce modern PHP practices.

Rector

Rector automates code refactoring and modernization.

task rector

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

  1. Always review changes before committing
  2. Run tests after applying transformations
  3. 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.

task tests:all          # Generate coverage reports
sonar-scanner           # Run analysis