1 # Shaarli, the personal, minimalist, super-fast, no-database delicious clone.
3 # Makefile for PHP code analysis & testing
6 # - install Composer, either:
7 # - from your distro's package manager;
8 # - from the official website (https://getcomposer.org/download/);
9 # - install/update test dependencies:
10 # $ 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
21 # These targets are non-blocking: || exit 0
23 static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary
28 # Detects PHP syntax errors
30 # Documentation (usage, output formatting):
31 # - http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php
32 # - http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php
34 code_sniffer: code_sniffer_full
36 # - errors by Git author
38 @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
40 # - all errors/warnings
42 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
44 # - errors grouped by kind
46 @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0
49 # PHP Copy/Paste Detector
51 # Detects code redundancy
53 # Documentation: https://github.com/sebastianbergmann/phpcpd
56 @echo "-----------------------"
57 @echo "PHP COPY/PASTE DETECTOR"
58 @echo "-----------------------"
59 @$(BIN)/phpcpd $(PHP_SOURCE) || exit 0
65 # Detects PHP syntax errors, sorted by category
67 # Rules documentation: http://phpmd.org/rules/index.html
70 @echo "-----------------"
71 @echo "PHP MESS DETECTOR"
72 @echo "-----------------"
75 mess_detector: mess_title
76 @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__'
79 # the generated HTML contains links to PHPMD's documentation
81 @$(BIN)/phpmd $(PHP_SOURCE) html $(MESS_DETECTOR_RULES) \
82 --reportfile phpmd.html || exit 0
84 # - warnings grouped by message, sorted by descending frequency order
85 mess_detector_grouped: mess_title
86 @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \
87 | cut -f 2 | sort | uniq -c | sort -nr
89 # - summary: number of warnings by rule set
90 mess_detector_summary: mess_title
91 @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \
92 warnings=$$($(BIN)/phpmd $(PHP_SOURCE) text $$rule | wc -l); \
93 printf "$$warnings\t$$rule\n"; \