Skip to content

Add Rector for automated code modernisation and refactoring #24

Description

@francescobianco

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions