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
11 # - install Xdebug for PHPUnit code coverage reports:
12 # - see http://xdebug.org/docs/install
16 PHP_SOURCE = index.php application tests
17 PHP_COMMA_SOURCE = index.php,application,tests
19 all: static_analysis_summary test
22 # Concise status of the project
23 # These targets are non-blocking: || exit 0
26 static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary
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
37 code_sniffer: code_sniffer_full
39 ### - errors by Git author
41 @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
43 ### - all errors/warnings
45 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
47 ### - errors grouped by kind
49 @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0
52 # PHP Copy/Paste Detector
53 # Detects code redundancy
54 # Documentation: https://github.com/sebastianbergmann/phpcpd
58 @echo "-----------------------"
59 @echo "PHP COPY/PASTE DETECTOR"
60 @echo "-----------------------"
61 @$(BIN)/phpcpd $(PHP_SOURCE) || exit 0
66 # Detects PHP syntax errors, sorted by category
67 # Rules documentation: http://phpmd.org/rules/index.html
69 MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode
72 @echo "-----------------"
73 @echo "PHP MESS DETECTOR"
74 @echo "-----------------"
77 mess_detector: mess_title
78 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__'
80 ### - all warnings + HTML output contains links to PHPMD's documentation
82 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) html $(MESS_DETECTOR_RULES) \
83 --reportfile phpmd.html || exit 0
85 ### - warnings grouped by message, sorted by descending frequency order
86 mess_detector_grouped: mess_title
87 @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \
88 | cut -f 2 | sort | uniq -c | sort -nr
90 ### - summary: number of warnings by rule set
91 mess_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"; \
99 # Runs unitary and functional tests
100 # Generates an HTML coverage report if Xdebug is enabled
102 # See phpunit.xml for configuration
103 # https://phpunit.de/manual/current/en/appendixes.configuration.html
109 @$(BIN)/phpunit tests
112 # Targets for repository and documentation maintenance
115 ### remove all unversioned files
119 ### update the local copy of the documentation
122 @git clone https://github.com/shaarli/Shaarli.wiki.git doc
125 ### Convert local markdown documentation to HTML
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"; \