Skip to content

Instantly share code, notes, and snippets.

@costdev
Created July 9, 2022 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save costdev/aa378e1e04c84b6f36752cbf548b320f to your computer and use it in GitHub Desktop.
Save costdev/aa378e1e04c84b6f36752cbf548b320f to your computer and use it in GitHub Desktop.
Convert non-Yoda to Yoda for backport.
#!/bin/bash
COMMIT=$1
BRANCH=$2
# Checkout the commit.
git checkout "$COMMIT"
# Undo the commit.
git reset --soft HEAD^
git restore --staged .
# Install the Slevomat coding standard.
yes | composer require "slevomat/coding-standard" "~7.0" --dev
# Apply the relevant autofix sniff.
vendor/bin/phpcbf $(git diff --name-only) --standard=SlevomatCodingStandard --sniffs=SlevomatCodingStandard.ControlStructures.RequireYodaComparison
# Remove the Slevomat coding standard.
yes | composer remove "slevomat/coding-standard" --dev
# Stash the changes.
git stash
# Switch to the commit branch.
git checkout "$BRANCH"
# Apply the stashed changes.
git stash pop
# The commit is now ready for final review before backporting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment