Skip to content

Instantly share code, notes, and snippets.

@adfinlay
Created May 28, 2018 08:54
Show Gist options
  • Save adfinlay/edba959abd6277820a43fbdde575ea0b to your computer and use it in GitHub Desktop.
Save adfinlay/edba959abd6277820a43fbdde575ea0b to your computer and use it in GitHub Desktop.
List unused Symfony routes and controller actions
#!/usr/bin/env bash
echo Unused routes
bin/console router:debug | awk '{ print $1 }' | sort | uniq | grep -vE '(_profiler|_wdt|_configurator|Name|router)' | xargs -I {} sh -c "echo {} \`git grep \'{}\' | wc -l\`" | awk '{ if ($2 == "0") print $1 }'
# If Symfony 2 use below (app/console instead of bin/console
#app/console router:debug | awk '{ print $1 }' | sort | uniq | grep -vE '(_profiler|_wdt|_configurator|Name|router)' | xargs -I {} sh -c "echo {} \`git grep \'{}\' | wc -l\`" | awk '{ if ($2 == "0") print $1 }'
echo Unused controller actions
grep -rE 'public function.*Action\(' src/ | grep Controller | awk '{ gsub(/src\/(Platformd|Velocity42)\//, ""); print }' | awk '{ gsub(/\/Controller\//, ":"); print }' | awk '{ gsub(/Controller\.php: public function /, ":"); print }' | awk -F 'Action' '{ print $1 }' | sort | uniq | xargs -I {} sh -c "echo {} \`git grep -i {} | wc -l\`" | awk '{ if ($2 == "0") print $1 }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment