Transpile to PHP 7.0 with Rector and manual replacements #77
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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 typefrom
function(): ?SchemaResolver {}
->function() {}
.: iterable
to fixFatal 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
-> `` asvoid
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)) {