Skip to content

Instantly share code, notes, and snippets.

@jacks0n
Created June 23, 2017 05:39
Show Gist options
  • Save jacks0n/56fd2d301c4faefc2eb8f10b25503869 to your computer and use it in GitHub Desktop.
Save jacks0n/56fd2d301c4faefc2eb8f10b25503869 to your computer and use it in GitHub Desktop.
# List all files with the wrong nameapace.
list_php_files_with_wrong_namespace() {
git ls-files --cached --modified '*.php' | while read PHP_FILE ; do
local EXPECTED_NAMESPACE="$(
echo "$PHP_FILE" | \
sed -e 's/^src\///' -e 's/\//\\/g' -e 's/\.php$//' | \
rev | cut -d'\' -f2- | rev
)"
local NAMESPACE="$(grep '^namespace ' "$PHP_FILE" | cut -d' ' -f2 | sed -e 's/;$//')"
if [[ "$NAMESPACE" != "$EXPECTED_NAMESPACE" ]] ; then
echo "$PHP_FILE"
echo "- Actual Namespace: $NAMESPACE"
echo "- Expected Namespace: $EXPECTED_NAMESPACE"
echo "\n"
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment