Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transpile to PHP 7.0 with Rector and manual replacements #77

Merged
merged 1 commit into from
Mar 19, 2024

Conversation

adamziel
Copy link
Collaborator

PHP 7.0 Compatibility

Makes the Blueprints library syntax–compatible with PHP >= 7.0 with automated transpilation and manual adjustments.

The automated transpilation is done with rector,
which downgrades features specific to PHP 7.2 and later features to PHP 7.1.

The manual part requires using regexps and editing the files by hand.

Automated part

To transpile the code to PHP 7.1, run:

# Install rector:
composer require rector/rector --ignore-platform-req=php

# Transpile:
php vendor/bin/rector process src

Unfortunately, Rector does not support downgrading to PHP 7.0 yet, so we need to do the
last stretch manually.

Manual part

Rector will downgrade PHP code to PHP 7.1 but not further. We need PHP 7.0 compat
so here's a few additional regexps to run. Regexps are not, of course, reliable in
the general case, but they seem to do the trick here.

List of manual replacements

  • : \?[a-zA-Z_0-9]+ -> (empty string) to remove the unsupported return type
    from function(): ?SchemaResolver {} -> function() {}.
  • : iterable to fix Fatal error: Generators may only declare a return type of Generator, Iterator or Traversable.
  • \?[a-zA-Z_0-9]+ \$ -> $ to remove the unsupported nullable type from function signatures,
    e.g. function(?Schema $schema){} -> function($schema){}.
  • (protected|public|private) const -> const as const visibility is not supported in PHP 7.0.
  • : void -> `` as void return type is unsupported in PHP 7.0.
  • [$ns, $name] = $this->parseName($name); -> list($ns, $name) = $this->parseName($name);
  • foreach ($data as [$cp, $chars]) { -> foreach ($data as list($cp, $chars)) {
  • Find or write Rector rules for downgrading to PHP 7.0

@adamziel
Copy link
Collaborator Author

There's plenty of formatting issues in this PR, let's reformat the entire repo in a follow-up one.

@adamziel adamziel merged commit adaf722 into trunk Mar 19, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant