PSR-2 Change for Flow and Neos

Flow and Neos switched to PSR-2 since 23 september 2015. Please make sure you update your forks of the development distributions as soon as possible to prevent rebase issues.

If you have to migrate a package yourself you can have a look at the steps we followed. We used the PHP-CS-Fixer which you can find on https://github.com/FriendsOfPHP/PHP-CS-Fixer

# First reformat the lowest released version
git checkout -B psr2-12 -t origin/1.2
php-cs-fixer fix . --level=psr2
< add to index >
git commit -m '[TASK] Reformat code to PSR-2 standard'

# Checkout the next released version
git checkout -B psr2-20 -t origin/2.0
php-cs-fixer fix . --level=psr2
< add to index >
git commit -m '[TASK] Reformat code to PSR-2 standard'

# Now we merge the lower version into the current branch
git merge -s ours psr2-12
<commit with [TASK] Prefix>

# And up to the master
git checkout -B psr2-master -t origin/master
php-cs-fixer fix . --level=psr2
< add to index >
git commit -m '[TASK] Reformat code to PSR-2 standard'

# And now we merge the lower version again
git merge -s ours psr2-20
<commit with [TASK] Prefix>

If you need to update a PR that was made before the PSR-2 change you might run into heavy conflicts while pulling / rebasing. If you run into that situation you can follow the following procedure.

1 Like

This change a problem for existing pull requests - because they won’t be mergeable anymore. After all, every line changed (spaces, not tabs) and the code was moved around (curly braces on new lines).

So, it needs some manual work, but the following appears to be a way to adjust the PRs that imposes as little work as possible. The following is assumed:

Below is a “recording” of updating a PR, removing all the output it boils down to:

» cd neos-development-distribution/Packages/Framework
» hub checkout https://github.com/neos/flow-development-collection/pull/42
» php-cs-fixer fix --level=psr2 TYPO3.Flow/Classes/TYPO3/Flow/Object/DependencyInjection/ProxyClassBuilder.php
» git commit -a --amend
» git checkout master
» git cherry-pick kitsunet-change39574~0
» git mergetool
» git cherry-pick --continue

The tricks here are the use of the hub command to easily checkout the PR (can be done without the tool, of course, just not as easy) and the fixing of the files that are actually important in the change with php-cs-fixer. Then the resulting amended commit is picked onto master (the target branch in this case) and can then be (force-) pushed to the original PR branch.


@dfeyer provided this snippet to run the php-cs-fixer on all file from the last commit (change HEAD to something else if needed):

for FILE in $(git diff-tree --no-commit-id --name-only -r HEAD); do 
  echo $FILE
  php-cs-fixer fix $FILE --level=psr2
done

The oneline function, useful to create an alias:

for FILE in $(git diff-tree --no-commit-id --name-only -r HEAD); do echo $FILE; php-cs-fixer fix $FILE --level=psr2; done


Here is the full session, including the output:

» cd neos-development-distribution/Packages/Framework
» hub checkout https://github.com/neos/flow-development-collection/pull/42
Branch kitsunet-change39574 set up to track remote branch change39574 from kitsunet by rebasing.
Switched to a new branch 'kitsunet-change39574'
» php-cs-fixer fix --level=psr2 TYPO3.Flow/Classes/TYPO3/Flow/Object/DependencyInjection/ProxyClassBuilder.php
   1) /Users/karsten/Projects/neos-development-distribution/Packages/Framework/TYPO3.Flow/Classes/TYPO3/Flow/Object/DependencyInjection/ProxyClassBuilder.php
Fixed all files in 1.782 seconds, 7.000 MB memory used
» git commit -a --amend
[kitsunet-change39574 9d0c7bd] [TASK] Compile list of properties information into proxy classes
 Author: Christian Mueller <christian@flownative.com>
 Date: Mon Sep 21 10:27:56 2015 +0200
 1 file changed, 780 insertions(+), 754 deletions(-)
 rewrite TYPO3.Flow/Classes/TYPO3/Flow/Object/DependencyInjection/ProxyClassBuilder.php (80%)
» git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'neos/master'.
» git cherry-pick kitsunet-change39574~0
error: could not apply 9d0c7bd... [TASK] Compile list of properties information into proxy classes
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
Framework ‹master*› » git mergetool
Merging:
TYPO3.Flow/Classes/TYPO3/Flow/Object/DependencyInjection/ProxyClassBuilder.php

Normal merge conflict for 'TYPO3.Flow/Classes/TYPO3/Flow/Object/DependencyInjection/ProxyClassBuilder.php':
  {local}: modified file
  {remote}: modified file
» git cherry-pick --continue
[master b644803] [TASK] Compile list of properties information into proxy classes
 Author: Christian Mueller <christian@flownative.com>
 Date: Mon Sep 21 10:27:56 2015 +0200
 1 file changed, 12 insertions(+), 5 deletions(-)
1 Like