aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.org>2015-02-25 22:08:50 +0100
committerVirtualTam <virtualtam@flibidi.org>2015-03-05 23:28:43 +0100
commit00f98bdacaba026e3d16aed36605bc21b72903ab (patch)
treea9cbb69f91ff7fee3a6f72dc87399a2034f95971
parent3a10fa0e3f0d0978dc359d1407b93fe425f44b25 (diff)
downloadShaarli-00f98bdacaba026e3d16aed36605bc21b72903ab.tar.gz
Shaarli-00f98bdacaba026e3d16aed36605bc21b72903ab.tar.zst
Shaarli-00f98bdacaba026e3d16aed36605bc21b72903ab.zip
Code quality: Makefile to run static code checkers
Relates to #71 Relates to #95 Additions: - Makefile for easy usage, - Composer file to declare dev & test dependencies. Features: - PHP Copy/Paste Detect: detect duplicate code; - PHP Code Sniffer: static analysis, syntax checking, - PHP Mess Detector: static analysis, syntax checking. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
-rw-r--r--.gitignore9
-rw-r--r--Makefile94
-rw-r--r--composer.json14
3 files changed, 116 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 6452c2c6..33d8a488 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,4 +10,11 @@ pagecache
10.project 10.project
11 11
12# Ignore raintpl generated pages 12# Ignore raintpl generated pages
13*.rtpl.php \ No newline at end of file 13*.rtpl.php
14
15# Ignore test dependencies
16composer.lock
17/vendor/
18
19# Ignore test output
20phpmd.html
diff --git a/Makefile b/Makefile
new file mode 100644
index 00000000..e17c8628
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,94 @@
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
12BIN = vendor/bin
13PHP_SOURCE = index.php
14MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode
15
16all: static_analysis_summary
17
18##
19# Concise status of the project
20#
21# These targets are non-blocking: || exit 0
22##
23static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary
24
25##
26# PHP_CodeSniffer
27#
28# Detects PHP syntax errors
29#
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
33##
34code_sniffer: code_sniffer_full
35
36# - errors by Git author
37code_sniffer_blame:
38 @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
39
40# - all errors/warnings
41code_sniffer_full:
42 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
43
44# - errors grouped by kind
45code_sniffer_source:
46 @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0
47
48##
49# PHP Copy/Paste Detector
50#
51# Detects code redundancy
52#
53# Documentation: https://github.com/sebastianbergmann/phpcpd
54##
55copy_paste:
56 @echo "-----------------------"
57 @echo "PHP COPY/PASTE DETECTOR"
58 @echo "-----------------------"
59 @$(BIN)/phpcpd $(PHP_SOURCE) || exit 0
60 @echo
61
62##
63# PHP Mess Detector
64#
65# Detects PHP syntax errors, sorted by category
66#
67# Rules documentation: http://phpmd.org/rules/index.html
68#
69mess_title:
70 @echo "-----------------"
71 @echo "PHP MESS DETECTOR"
72 @echo "-----------------"
73
74# - all warnings
75mess_detector: mess_title
76 @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__'
77
78# - all warnings
79# the generated HTML contains links to PHPMD's documentation
80mess_detector_html:
81 @$(BIN)/phpmd $(PHP_SOURCE) html $(MESS_DETECTOR_RULES) \
82 --reportfile phpmd.html || exit 0
83
84# - warnings grouped by message, sorted by descending frequency order
85mess_detector_grouped: mess_title
86 @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \
87 | cut -f 2 | sort | uniq -c | sort -nr
88
89# - summary: number of warnings by rule set
90mess_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"; \
94 done;
diff --git a/composer.json b/composer.json
new file mode 100644
index 00000000..d1f613c1
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,14 @@
1{
2 "name": "shaarli/shaarli",
3 "description": "The personal, minimalist, super-fast, no-database delicious clone",
4 "license": "MIT",
5 "support": {
6 "issues": "https://github.com/shaarli/Shaarli/issues"
7 },
8 "require": {},
9 "require-dev": {
10 "phpmd/phpmd" : "@stable",
11 "sebastian/phpcpd": "*",
12 "squizlabs/php_codesniffer": "2.*"
13 }
14}