]> git.immae.eu Git - github/shaarli/Shaarli.git/blame_incremental - Makefile
Makefile: do not call `clean` before `test`
[github/shaarli/Shaarli.git] / Makefile
... / ...
CommitLineData
1# Shaarli, the personal, minimalist, super-fast, no-database delicious clone.
2# Makefile for PHP code analysis & testing
3
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
11# - install Xdebug for PHPUnit code coverage reports:
12# - see http://xdebug.org/docs/install
13# - enable in php.ini
14
15BIN = vendor/bin
16PHP_SOURCE = index.php application tests
17PHP_COMMA_SOURCE = index.php,application,tests
18
19all: static_analysis_summary test
20
21##
22# Concise status of the project
23# These targets are non-blocking: || exit 0
24##
25
26static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary
27 @echo
28
29##
30# PHP_CodeSniffer
31# Detects PHP syntax errors
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##
36
37code_sniffer: code_sniffer_full
38
39### - errors by Git author
40code_sniffer_blame:
41 @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
42
43### - all errors/warnings
44code_sniffer_full:
45 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
46
47### - errors grouped by kind
48code_sniffer_source:
49 @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0
50
51##
52# PHP Copy/Paste Detector
53# Detects code redundancy
54# Documentation: https://github.com/sebastianbergmann/phpcpd
55##
56
57copy_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
66# Detects PHP syntax errors, sorted by category
67# Rules documentation: http://phpmd.org/rules/index.html
68##
69MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode
70
71mess_title:
72 @echo "-----------------"
73 @echo "PHP MESS DETECTOR"
74 @echo "-----------------"
75
76### - all warnings
77mess_detector: mess_title
78 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__'
79
80### - all warnings + HTML output contains links to PHPMD's documentation
81mess_detector_html:
82 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) html $(MESS_DETECTOR_RULES) \
83 --reportfile phpmd.html || exit 0
84
85### - warnings grouped by message, sorted by descending frequency order
86mess_detector_grouped: mess_title
87 @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \
88 | cut -f 2 | sort | uniq -c | sort -nr
89
90### - summary: number of warnings by rule set
91mess_detector_summary: mess_title
92 @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \
93 warnings=$$($(BIN)/phpmd $(PHP_COMMA_SOURCE) text $$rule | wc -l); \
94 printf "$$warnings\t$$rule\n"; \
95 done;
96
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##
105test:
106 @echo "-------"
107 @echo "PHPUNIT"
108 @echo "-------"
109 @$(BIN)/phpunit tests
110
111##
112# Targets for repository and documentation maintenance
113##
114
115### remove all unversioned files
116clean:
117 @git clean -df
118
119### update the local copy of the documentation
120doc: clean
121 @rm -rf doc
122 @git clone https://github.com/shaarli/Shaarli.wiki.git doc
123 @rm -rf doc/.git
124
125### Convert local markdown documentation to HTML
126htmldoc:
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"; \
129 done;