Makefile 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. # - install Xdebug for PHPUnit code coverage reports:
  11. # - see http://xdebug.org/docs/install
  12. # - enable in php.ini
  13. BIN = vendor/bin
  14. PHP_SOURCE = index.php application tests
  15. PHP_COMMA_SOURCE = index.php,application,tests
  16. all: static_analysis_summary test
  17. ##
  18. # Concise status of the project
  19. # These targets are non-blocking: || exit 0
  20. ##
  21. static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary
  22. @echo
  23. ##
  24. # PHP_CodeSniffer
  25. # Detects PHP syntax errors
  26. # Documentation (usage, output formatting):
  27. # - http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php
  28. # - http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php
  29. ##
  30. code_sniffer: code_sniffer_full
  31. ### - errors by Git author
  32. code_sniffer_blame:
  33. @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
  34. ### - all errors/warnings
  35. code_sniffer_full:
  36. @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
  37. ### - errors grouped by kind
  38. code_sniffer_source:
  39. @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0
  40. ##
  41. # PHP Copy/Paste Detector
  42. # Detects code redundancy
  43. # Documentation: https://github.com/sebastianbergmann/phpcpd
  44. ##
  45. copy_paste:
  46. @echo "-----------------------"
  47. @echo "PHP COPY/PASTE DETECTOR"
  48. @echo "-----------------------"
  49. @$(BIN)/phpcpd $(PHP_SOURCE) || exit 0
  50. @echo
  51. ##
  52. # PHP Mess Detector
  53. # Detects PHP syntax errors, sorted by category
  54. # Rules documentation: http://phpmd.org/rules/index.html
  55. ##
  56. MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode
  57. mess_title:
  58. @echo "-----------------"
  59. @echo "PHP MESS DETECTOR"
  60. @echo "-----------------"
  61. ### - all warnings
  62. mess_detector: mess_title
  63. @$(BIN)/phpmd $(PHP_COMMA_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__'
  64. ### - all warnings + HTML output contains links to PHPMD's documentation
  65. mess_detector_html:
  66. @$(BIN)/phpmd $(PHP_COMMA_SOURCE) html $(MESS_DETECTOR_RULES) \
  67. --reportfile phpmd.html || exit 0
  68. ### - warnings grouped by message, sorted by descending frequency order
  69. mess_detector_grouped: mess_title
  70. @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \
  71. | cut -f 2 | sort | uniq -c | sort -nr
  72. ### - summary: number of warnings by rule set
  73. mess_detector_summary: mess_title
  74. @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \
  75. warnings=$$($(BIN)/phpmd $(PHP_COMMA_SOURCE) text $$rule | wc -l); \
  76. printf "$$warnings\t$$rule\n"; \
  77. done;
  78. ##
  79. # PHPUnit
  80. # Runs unitary and functional tests
  81. # Generates an HTML coverage report if Xdebug is enabled
  82. #
  83. # See phpunit.xml for configuration
  84. # https://phpunit.de/manual/current/en/appendixes.configuration.html
  85. ##
  86. test: clean
  87. @echo "-------"
  88. @echo "PHPUNIT"
  89. @echo "-------"
  90. @$(BIN)/phpunit tests
  91. ##
  92. # Targets for repository and documentation maintenance
  93. ##
  94. ### remove all unversioned files
  95. clean:
  96. @git clean -df
  97. ### update the local copy of the documentation
  98. doc: clean
  99. @rm -rf doc
  100. @git clone https://github.com/shaarli/Shaarli.wiki.git doc
  101. @rm -rf doc/.git
  102. ### Convert local markdown documentation to HTML
  103. htmldoc:
  104. for file in `find doc/ -maxdepth 1 -name "*.md"`; do \
  105. pandoc -f markdown_github -t html5 -s -c "github-markdown.css" -o doc/`basename $$file .md`.html "$$file"; \
  106. done;