Skip to content

Instantly share code, notes, and snippets.

@sbine
Last active August 29, 2015 14:17
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 sbine/36b4e78255de972a84ac to your computer and use it in GitHub Desktop.
Save sbine/36b4e78255de972a84ac to your computer and use it in GitHub Desktop.
Identify namespace dependency issues (Laravel 4 to Laravel 5 upgrade)
#!/bin/bash
folder='*'
exclude='--exclude-dir=vendor --exclude-dir=bower_components --exclude-dir=node_modules --exclude-dir=storage --exclude-dir=public'
statics=`grep -Eo $exclude "([A-Z][a-zA-Z0-9]+)::" $folder -R`
classes=`grep -Eo $exclude 'new ([A-Z][a-zA-Z0-9]+)' $folder -R | sed -n 's/new //p'`
exceptions=`grep -Eo $exclude 'catch \((([A-Z][a-zA-Z0-9]+)?Exception)' $folder -R | sed -n 's/catch (//p'`
combined=("${statics[@]}" "${classes[@]}" "${exceptions[@]}")
combined=`echo "${combined[@]}" | sort | uniq`
for classUsage in $combined; do
tempArray=($(echo $classUsage | tr ":" " "))
if [ ! -z ${tempArray[1]} ]; then
useStatementExists=`grep -E "^use ([^ ]+)?( as )?${tempArray[1]};$" ${tempArray[0]}`
if [ -z "$useStatementExists" ]; then
echo "${tempArray[@]}"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment