Skip to content

Instantly share code, notes, and snippets.

@joereynolds
Last active February 7, 2021 11:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joereynolds/1cdc040605d7751714b7ef66e77d4795 to your computer and use it in GitHub Desktop.
Save joereynolds/1cdc040605d7751714b7ef66e77d4795 to your computer and use it in GitHub Desktop.
Rough and naive script to find unused functions in php files
#!/bin/bash
function report_unused_functions() {
# Find the function
# Remove the ampersands for pass by reference functions
# Remove everything after and including the ( in the function name
git grep -Ei '(public|private|protected) function' $1 | awk '{print $4}' | tr -d '&' | cut -f1 -d"(" | while read -r function ; do
match_count="$(git grep -i $function| wc -l)"
if [ "$match_count" -lt 2 ]; then
echo "$function can be removed. $match_count match"
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment