Makefile 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # Shaarli, the personal, minimalist, super-fast, no-database delicious clone.
  2. # Makefile for PHP code analysis & testing
  3. # Prerequisites:
  4. # - install Composer, either:
  5. # - from your distro's package manager;
  6. # - from the official website (https://getcomposer.org/download/);
  7. # - install/update test dependencies:
  8. # $ composer install # 1st setup
  9. # $ composer update
  10. BIN = vendor/bin
  11. PHP_SOURCE = index.php
  12. MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode
  13. all: static_analysis_summary
  14. ##
  15. # Concise status of the project
  16. # These targets are non-blocking: || exit 0
  17. ##
  18. static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary
  19. ##
  20. # PHP_CodeSniffer
  21. # Detects PHP syntax errors
  22. # Documentation (usage, output formatting):
  23. # - http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php
  24. # - http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php
  25. ##
  26. code_sniffer: code_sniffer_full
  27. ### - errors by Git author
  28. code_sniffer_blame:
  29. @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
  30. ### - all errors/warnings
  31. code_sniffer_full:
  32. @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
  33. ### - errors grouped by kind
  34. code_sniffer_source:
  35. @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0
  36. ##
  37. # PHP Copy/Paste Detector
  38. # Detects code redundancy
  39. # Documentation: https://github.com/sebastianbergmann/phpcpd
  40. ##
  41. copy_paste:
  42. @echo "-----------------------"
  43. @echo "PHP COPY/PASTE DETECTOR"
  44. @echo "-----------------------"
  45. @$(BIN)/phpcpd $(PHP_SOURCE) || exit 0
  46. @echo
  47. ##
  48. # PHP Mess Detector
  49. # Detects PHP syntax errors, sorted by category
  50. # Rules documentation: http://phpmd.org/rules/index.html
  51. ##
  52. mess_title:
  53. @echo "-----------------"
  54. @echo "PHP MESS DETECTOR"
  55. @echo "-----------------"
  56. ### - all warnings
  57. mess_detector: mess_title
  58. @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__'
  59. ### - all warnings + HTML output contains links to PHPMD's documentation
  60. mess_detector_html:
  61. @$(BIN)/phpmd $(PHP_SOURCE) html $(MESS_DETECTOR_RULES) \
  62. --reportfile phpmd.html || exit 0
  63. ### - warnings grouped by message, sorted by descending frequency order
  64. mess_detector_grouped: mess_title
  65. @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \
  66. | cut -f 2 | sort | uniq -c | sort -nr
  67. ### - summary: number of warnings by rule set
  68. mess_detector_summary: mess_title
  69. @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \
  70. warnings=$$($(BIN)/phpmd $(PHP_SOURCE) text $$rule | wc -l); \
  71. printf "$$warnings\t$$rule\n"; \
  72. done;
  73. ##
  74. # Targets for repository and documentation maintenance
  75. ##
  76. ### remove all unversioned files
  77. clean:
  78. @git clean -df
  79. ### update the local copy of the documentation
  80. doc: clean
  81. @rm -rf doc
  82. @git clone https://github.com/shaarli/Shaarli.wiki.git doc
  83. @rm -rf doc/.git
  84. ### Convert local markdown documentation to HTML
  85. htmldoc:
  86. for file in `find doc/ -maxdepth 1 -name "*.md"`; do \
  87. pandoc -f markdown_github -t html5 -s -c "github-markdown.css" -o doc/`basename $$file .md`.html "$$file"; \
  88. done;