Last active
February 7, 2021 11:31
-
-
Save joereynolds/1cdc040605d7751714b7ef66e77d4795 to your computer and use it in GitHub Desktop.
Rough and naive script to find unused functions in php files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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