]>
Commit | Line | Data |
---|---|---|
00f98bda | 1 | # Shaarli, the personal, minimalist, super-fast, no-database delicious clone. |
00f98bda | 2 | # Makefile for PHP code analysis & testing |
f3e89f50 | 3 | |
00f98bda V |
4 | # Prerequisites: |
5 | # - install Composer, either: | |
6 | # - from your distro's package manager; | |
7 | # - from the official website (https://getcomposer.org/download/); | |
8 | # - install/update test dependencies: | |
9 | # $ composer install # 1st setup | |
10 | # $ composer update | |
ca74886f V |
11 | # - install Xdebug for PHPUnit code coverage reports: |
12 | # - see http://xdebug.org/docs/install | |
13 | # - enable in php.ini | |
f3e89f50 | 14 | |
00f98bda | 15 | BIN = vendor/bin |
ca74886f V |
16 | PHP_SOURCE = index.php application tests |
17 | PHP_COMMA_SOURCE = index.php,application,tests | |
00f98bda | 18 | |
ca74886f | 19 | all: static_analysis_summary test |
00f98bda V |
20 | |
21 | ## | |
22 | # Concise status of the project | |
00f98bda V |
23 | # These targets are non-blocking: || exit 0 |
24 | ## | |
f3e89f50 | 25 | |
00f98bda | 26 | static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary |
ca74886f | 27 | @echo |
00f98bda V |
28 | |
29 | ## | |
30 | # PHP_CodeSniffer | |
00f98bda | 31 | # Detects PHP syntax errors |
00f98bda V |
32 | # Documentation (usage, output formatting): |
33 | # - http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php | |
34 | # - http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php | |
35 | ## | |
f3e89f50 | 36 | |
00f98bda V |
37 | code_sniffer: code_sniffer_full |
38 | ||
f3e89f50 | 39 | ### - errors by Git author |
00f98bda V |
40 | code_sniffer_blame: |
41 | @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame | |
42 | ||
f3e89f50 | 43 | ### - all errors/warnings |
00f98bda V |
44 | code_sniffer_full: |
45 | @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 | |
46 | ||
f3e89f50 | 47 | ### - errors grouped by kind |
00f98bda V |
48 | code_sniffer_source: |
49 | @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0 | |
50 | ||
51 | ## | |
52 | # PHP Copy/Paste Detector | |
00f98bda | 53 | # Detects code redundancy |
00f98bda V |
54 | # Documentation: https://github.com/sebastianbergmann/phpcpd |
55 | ## | |
f3e89f50 | 56 | |
00f98bda V |
57 | copy_paste: |
58 | @echo "-----------------------" | |
59 | @echo "PHP COPY/PASTE DETECTOR" | |
60 | @echo "-----------------------" | |
61 | @$(BIN)/phpcpd $(PHP_SOURCE) || exit 0 | |
62 | @echo | |
63 | ||
64 | ## | |
65 | # PHP Mess Detector | |
00f98bda | 66 | # Detects PHP syntax errors, sorted by category |
00f98bda | 67 | # Rules documentation: http://phpmd.org/rules/index.html |
f3e89f50 | 68 | ## |
ca74886f | 69 | MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode |
f3e89f50 | 70 | |
00f98bda V |
71 | mess_title: |
72 | @echo "-----------------" | |
73 | @echo "PHP MESS DETECTOR" | |
74 | @echo "-----------------" | |
75 | ||
f3e89f50 | 76 | ### - all warnings |
00f98bda | 77 | mess_detector: mess_title |
ca74886f | 78 | @$(BIN)/phpmd $(PHP_COMMA_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__' |
00f98bda | 79 | |
f3e89f50 | 80 | ### - all warnings + HTML output contains links to PHPMD's documentation |
00f98bda | 81 | mess_detector_html: |
ca74886f | 82 | @$(BIN)/phpmd $(PHP_COMMA_SOURCE) html $(MESS_DETECTOR_RULES) \ |
00f98bda V |
83 | --reportfile phpmd.html || exit 0 |
84 | ||
f3e89f50 | 85 | ### - warnings grouped by message, sorted by descending frequency order |
00f98bda V |
86 | mess_detector_grouped: mess_title |
87 | @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \ | |
88 | | cut -f 2 | sort | uniq -c | sort -nr | |
89 | ||
f3e89f50 | 90 | ### - summary: number of warnings by rule set |
00f98bda V |
91 | mess_detector_summary: mess_title |
92 | @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \ | |
ca74886f | 93 | warnings=$$($(BIN)/phpmd $(PHP_COMMA_SOURCE) text $$rule | wc -l); \ |
00f98bda V |
94 | printf "$$warnings\t$$rule\n"; \ |
95 | done; | |
1acc87ee | 96 | |
ca74886f V |
97 | ## |
98 | # PHPUnit | |
99 | # Runs unitary and functional tests | |
100 | # Generates an HTML coverage report if Xdebug is enabled | |
101 | # | |
102 | # See phpunit.xml for configuration | |
103 | # https://phpunit.de/manual/current/en/appendixes.configuration.html | |
104 | ## | |
105 | test: clean | |
106 | @echo "-------" | |
107 | @echo "PHPUNIT" | |
108 | @echo "-------" | |
109 | @$(BIN)/phpunit tests | |
110 | ||
1acc87ee | 111 | ## |
112 | # Targets for repository and documentation maintenance | |
f3e89f50 | 113 | ## |
114 | ||
115 | ### remove all unversioned files | |
1acc87ee | 116 | clean: |
117 | @git clean -df | |
118 | ||
f3e89f50 | 119 | ### update the local copy of the documentation |
1acc87ee | 120 | doc: clean |
121 | @rm -rf doc | |
122 | @git clone https://github.com/shaarli/Shaarli.wiki.git doc | |
123 | @rm -rf doc/.git | |
82af78b2 | 124 | |
125 | ### Convert local markdown documentation to HTML | |
126 | htmldoc: | |
127 | for file in `find doc/ -maxdepth 1 -name "*.md"`; do \ | |
128 | pandoc -f markdown_github -t html5 -s -c "github-markdown.css" -o doc/`basename $$file .md`.html "$$file"; \ | |
ca74886f | 129 | done; |