Skip to content

Instantly share code, notes, and snippets.

@Gydo194
Created January 15, 2020 15:38
Show Gist options
  • Save Gydo194/347a391748bdf88987d2b4d5f288fae8 to your computer and use it in GitHub Desktop.
Save Gydo194/347a391748bdf88987d2b4d5f288fae8 to your computer and use it in GitHub Desktop.
PHP Class diagram generator shell script
#!/bin/bash
if [[ $# -ne 1 ]]; then
echo "No file specified"
exit
fi
FILE=$1
#public properties
egrep 'public \$[a-zA-Z_]' $FILE | tr -d '$;=[]' | awk '{print "+ " $2}'
echo
#private properties
egrep 'private \$[a-zA-Z_]' $FILE | tr -d '$;=[]' | awk '{print "- " $2}'
echo "-------------------------------------------------------------"
#getters
egrep 'public function get[A-Za-z]' $FILE | tr -d ':' | awk '{print "+ " $3}'
echo
#setters
egrep 'public function set[A-Za-z]' $FILE | tr -d '$:=[]?' | awk '{$1=""; $2=""; $NF=""; gsub(/^[ \t]+/, "", $0); print "+ " $0}' | sed 's/[[:space:]])/)/g'
echo
#public functions
egrep 'public function [^set|get][A-Za-z]' $FILE | tr -d '$:=[]?' | awk '{$1=""; $2=""; $NF=""; gsub(/^[ \t]+/, "", $0); print "+ " $0}' | sed 's/[[:space:]])/)/g'
echo
#private functions
egrep 'private function [^set|get][A-Za-z]' $FILE | tr -d '$:=[]?' | awk '{$1=""; $2=""; $NF=""; gsub(/^[ \t]+/, "", $0); print "+ " $0}' | sed 's/[[:space:]])/)/g'
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment