devel:coding_style
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
devel:coding_style [2012-10-25 04:43] – Spelling: Lineendings -> Line Endings Matt2 | devel:coding_style [2019-01-07 20:30] – [Checking for Coding Style Violations] Add 3.x standards path phy25 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Coding Style ====== | ====== Coding Style ====== | ||
- | There are currently no really strict rules in how the code should be formatted but a few basic things should be attended to when adding code to DokuWiki. | + | There are currently no really strict rules in how the code should be formatted, but a few basic things should be attended to when adding code to DokuWiki. |
+ | It should be noted that for the DokuWiki core applying of the PSR2 coding style is work in progress (branch '' | ||
===== Brackets and Indentations ===== | ===== Brackets and Indentations ===== | ||
Line 22: | Line 23: | ||
===== Line Endings ===== | ===== Line Endings ===== | ||
- | Lines should end with a single linefeed character (UNIX style). Please try to avoid trailing whitespace. Have a look at our page about [[VIM]] to see how to set up VIM to spot these easily. | + | Lines should end with a single linefeed character (UNIX style). Please try to avoid trailing whitespace. Have a look at our page about [[Vim]] to see how to set up Vim to spot these easily. |
Line 42: | Line 43: | ||
* | * | ||
*/ | */ | ||
- | function is_foo($in){ | + | function is_foo($in) { |
- | ... | + | ... |
} | } | ||
</ | </ | ||
- | These comments are used for the [[http:// | + | These comments are used for the [[xref> |
- | + | ===== PHP Closing Tags ===== | |
- | ===== PHP closing tags ===== | + | |
You should omit PHP's closing tags (''?>'' | You should omit PHP's closing tags (''?>'' | ||
> **Note:** The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include() | > **Note:** The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include() | ||
+ | |||
+ | ===== Visibility ===== | ||
+ | |||
+ | Even though some core code still uses PHP4 compatible '' | ||
+ | |||
+ | Please do not use '' | ||
===== Checking for Coding Style Violations ===== | ===== Checking for Coding Style Violations ===== | ||
- | The development [[git]] checkout contains a coding standard setup for the use with [[http:// | + | The development [[Git]] checkout contains a coding standard setup for the use with [[http:// |
+ | |||
+ | === Setup === | ||
+ | |||
+ | To install PHP_CodeSniffer run the following in your shell. | ||
+ | |||
+ | pear install PHP_CodeSniffer | ||
+ | |||
+ | Link the DokuWiki coding standard to the CodeSniffer directory. | ||
+ | |||
+ | # PHP_CodeSniffer Version 2.x | ||
+ | ln -s / | ||
+ | |||
+ | # PHP_CodeSniffer Version 3.x | ||
+ | ln -s / | ||
+ | |||
+ | Set DokuWiki to be the default standard. | ||
+ | |||
+ | phpcs --config-set default_standard DokuWiki | ||
+ | |||
+ | Note that the provided DokuWiki coding standard is for PHP_CodeSniffer 2.x. PHP_CodeSniffer 3.x has breaking changes which result in errors indicating that the interface '' | ||
+ | |||
+ | === Usage === | ||
+ | |||
+ | You can use PHP_CodeSniffer to check a single file or an entire directory including subdirectories using the following commands. | ||
+ | |||
+ | # Check a single file | ||
+ | phpcs myfile.php | ||
+ | |||
+ | # Check all files in a directory | ||
+ | phpcs / | ||
devel/coding_style.txt · Last modified: 2023-11-13 21:13 by andi