1 # Shaarli, the personal, minimalist, super-fast, no-database delicious clone.
2 # Makefile for PHP code analysis & testing
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
13 PHP_SOURCE = index.php
14 MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode
16 all: static_analysis_summary
19 # Concise status of the project
20 # These targets are non-blocking: || exit 0
23 static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary
27 # Detects PHP syntax errors
28 # Documentation (usage, output formatting):
29 # - http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php
30 # - http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php
33 code_sniffer: code_sniffer_full
35 ### - errors by Git author
37 @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
39 ### - all errors/warnings
41 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
43 ### - errors grouped by kind
45 @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0
48 # PHP Copy/Paste Detector
49 # Detects code redundancy
50 # Documentation: https://github.com/sebastianbergmann/phpcpd
54 @echo "-----------------------"
55 @echo "PHP COPY/PASTE DETECTOR"
56 @echo "-----------------------"
57 @$(BIN)/phpcpd $(PHP_SOURCE) || exit 0
62 # Detects PHP syntax errors, sorted by category
63 # Rules documentation: http://phpmd.org/rules/index.html
67 @echo "-----------------"
68 @echo "PHP MESS DETECTOR"
69 @echo "-----------------"
72 mess_detector: mess_title
73 @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__'
75 ### - all warnings + HTML output contains links to PHPMD's documentation
77 @$(BIN)/phpmd $(PHP_SOURCE) html $(MESS_DETECTOR_RULES) \
78 --reportfile phpmd.html || exit 0
80 ### - warnings grouped by message, sorted by descending frequency order
81 mess_detector_grouped: mess_title
82 @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \
83 | cut -f 2 | sort | uniq -c | sort -nr
85 ### - summary: number of warnings by rule set
86 mess_detector_summary: mess_title
87 @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \
88 warnings=$$($(BIN)/phpmd $(PHP_SOURCE) text $$rule | wc -l); \
89 printf "$$warnings\t$$rule\n"; \
93 # Targets for repository and documentation maintenance
96 ### remove all unversioned files
100 ### update the local copy of the documentation
103 @git clone https://github.com/shaarli/Shaarli.wiki.git doc
106 ### Convert local markdown documentation to HTML
108 for file in `find doc/ -maxdepth 1 -name "*.md"`; do \
109 pandoc -f markdown_github -t html5 -s -c "github-markdown.css" -o doc/`basename $$file .md`.html "$$file"; \