Makefile 2.8 KB

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