diff options
author | nodiscc <nodiscc@gmail.com> | 2015-03-07 01:19:06 +0100 |
---|---|---|
committer | nodiscc <nodiscc@gmail.com> | 2015-03-07 01:19:06 +0100 |
commit | 1c8f4fc1074500329edd67301fa445d71976dfc1 (patch) | |
tree | a9cbb69f91ff7fee3a6f72dc87399a2034f95971 | |
parent | 3a10fa0e3f0d0978dc359d1407b93fe425f44b25 (diff) | |
parent | 00f98bdacaba026e3d16aed36605bc21b72903ab (diff) | |
download | Shaarli-1c8f4fc1074500329edd67301fa445d71976dfc1.tar.gz Shaarli-1c8f4fc1074500329edd67301fa445d71976dfc1.tar.zst Shaarli-1c8f4fc1074500329edd67301fa445d71976dfc1.zip |
Merge pull request #124 from virtualtam/static-analysis
Code quality: Makefile to run static code checkers
-rw-r--r-- | .gitignore | 9 | ||||
-rw-r--r-- | Makefile | 94 | ||||
-rw-r--r-- | composer.json | 14 |
3 files changed, 116 insertions, 1 deletions
@@ -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 | ||
16 | composer.lock | ||
17 | /vendor/ | ||
18 | |||
19 | # Ignore test output | ||
20 | phpmd.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 | ||
12 | BIN = vendor/bin | ||
13 | PHP_SOURCE = index.php | ||
14 | MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode | ||
15 | |||
16 | all: static_analysis_summary | ||
17 | |||
18 | ## | ||
19 | # Concise status of the project | ||
20 | # | ||
21 | # These targets are non-blocking: || exit 0 | ||
22 | ## | ||
23 | static_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 | ## | ||
34 | code_sniffer: code_sniffer_full | ||
35 | |||
36 | # - errors by Git author | ||
37 | code_sniffer_blame: | ||
38 | @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame | ||
39 | |||
40 | # - all errors/warnings | ||
41 | code_sniffer_full: | ||
42 | @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 | ||
43 | |||
44 | # - errors grouped by kind | ||
45 | code_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 | ## | ||
55 | copy_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 | # | ||
69 | mess_title: | ||
70 | @echo "-----------------" | ||
71 | @echo "PHP MESS DETECTOR" | ||
72 | @echo "-----------------" | ||
73 | |||
74 | # - all warnings | ||
75 | mess_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 | ||
80 | mess_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 | ||
85 | mess_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 | ||
90 | mess_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 | } | ||