openapi-php-sdk icon indicating copy to clipboard operation
openapi-php-sdk copied to clipboard

Add Rector for automated code modernisation and refactoring

Open francescobianco opened this issue 6 months ago • 0 comments

Motivation

As PHP evolves and the SDK targets PHP 8.0+, there are patterns that could be automatically modernised: constructor promotion, match expressions, named arguments, and more.

Example

Current code in src/Client.php:

public function __construct(?string $token = null, ...)
{
    $this->token = $token ?? getenv('OPEN_API_TOKEN');
    ...
}

With Rector + constructor promotion this could become:

public function __construct(
    private ?string $token = null,
    ...
) {
    $this->token ??= getenv('OPEN_API_TOKEN');
}

Proposal

  • Add rector/rector to require-dev
  • Configure a rector.php with the LevelSetList::UP_TO_PHP_81 preset
  • Add a composer run rector script for dry-run and composer run rector-fix to apply

Open questions

  • Should Rector run in CI as a check-only step, or only locally?
  • Which rule sets are safe to apply without risking breaking changes for consumers on PHP 8.0?

francescobianco avatar May 08 '26 16:05 francescobianco