-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp.extractClassSymbols
executable file
·79 lines (67 loc) · 1.56 KB
/
php.extractClassSymbols
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
usage() {
detail "usage : $(basename "$0") [ --filter expression ]"
doc=(
"echoes a list of class with their"
"" "List of flags :"
"-h | --help displays help"
"--filter expression removes expression from results"
"--only expression removes not matching from results"
)
detail --printf -- " %s\n" "${doc[@]}"
}
filters=()
only=()
while test "$#" -gt 0; do
case "$1" in
"-h" | "--help")
usage
exit
;;
--filter)
shift
if [ "$#" -lt 1 ]; then
exitError 1 "Missing argument for filter"
fi
filters+=("$1")
;;
--only)
shift
if [ "$#" -lt 1 ]; then
exitError 1 "Missing argument for only"
fi
only+=("$1")
;;
esac
shift
done
filter='$^'
if [ "${#filters[@]}" -gt 0 ]; then
filter=$(printf "|(%s)" "${filters[@]}")
filter=${filter:1}
fi
mapfile -t lines < <(
find . -name "*.php" -exec ag "^[ \t]*\b(interface|(abstract )?class|trait)\b" {} '+' |
grep -vP "\b(lib|vendor)\b" |
php.makeClassHierarchyPipeline | sort -u | uniq | grep -viP "$filter" |
matchAll "${only[@]}"
)
symbols=()
for line in "${lines[@]}"; do
symbol=${lines%%\'*}
symbols+=("$symbol")
done
mapfile -t duplicates < <(printf "%s\n" "${symbols[@]}" | uniq -c | sed -re '/\b1\b/d' -re 's#^\s+[0-9]+\s+##g')
if [ -n "${duplicates[*]}" ]; then
printf "Duplicate found: %s\n" "${duplicates[@]}" >&2
fi
echo "<?php"
echo "# filtered : $filter"
printf "# only : "
printf "%s " "${only[@]}"
printf "\n"
echo "return ["
printf " %s\n" "${lines[@]}"
echo "];"