X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=doc%2FDevelopers-Intro.md;h=61b300b0cc2f5c876f53e6dd51d7b7b613bcfabd;hb=221cfa8c22b724228ed24618569cabcae582d331;hp=78da231b6c9b165e64b864d0dd70b39dbdc9d6eb;hpb=3a9be01cb6de8a412809c80a2c5a52a952c678ba;p=friendica.git diff --git a/doc/Developers-Intro.md b/doc/Developers-Intro.md index 78da231b6c..61b300b0cc 100644 --- a/doc/Developers-Intro.md +++ b/doc/Developers-Intro.md @@ -49,20 +49,41 @@ Programming ###Coding standards -For the sake of consistency between contribution and general code readability, Friendica follows the widespread [PSR-2 coding standards](http://www.php-fig.org/psr/psr-2/). -Don't worry, you don't have to know by heart the PSR-2 coding standards to start contributing to Friendica. -Before comitting your work, you can use the PHP Coding Standard Fixer located in the `util` folder this way: - - $> php util/php-cs-fixer.phar fix --level=psr2 - -Here's a few primers if you are new to the PSR-2 coding standards: - * Indentation is 4 spaces, period. +For the sake of consistency between contribution and general code readability, Friendica follows the widespread [PSR-2 coding standards](http://www.php-fig.org/psr/psr-2/) to the exception of a few rules. +Here's a few primers if you are new to Friendica or to the PSR-2 coding standards: + * Indentation is tabs, period (not PSR-2). * By default, strings are enclosed in single quotes, but feel free to use double quotes if it makes more sense (SQL queries, adding tabs and line feeds). * Operators are wrapped by spaces, e.g. `$var === true`, `$var = 1 + 2` and `'string' . $concat . 'enation'` * Braces are mandatory in conditions * No closing PHP tag * No trailing spaces +Don't worry, you don't have to know by heart the PSR-2 coding standards to start contributing to Friendica. +There are a few tools you can use to check or fix your files before you commit. + +For documentation we use the standard of *one sentence per line* for the `md` files in the `/doc` and `/doc/$lng` subdirectories. + +####Check with [PHP Code Sniffer](https://github.com/squizlabs/PHP_CodeSniffer) + +This tool checks your files against a variety of coding standards, including PSR-2, and ouputs a report of all the standard violations. +You can simply install it through PEAR: `pear install PHP_CodeSniffer` +Once it is installed and available in your PATH, here's the command to run before committing your work: + + $> phpcs --standard=PSR2 + +The output is a list of all the coding standards violations that you should fix before committing your work. +Additionally, `phpcs` integrates with a few IDEs (Eclipse, Netbeans, PHPStorm...) so that you don't have to fiddle with the command line. + +####Fix with PHP Code Beautifier and Fixer (phpbcf) included in PHP Code Sniffer + +If you're getting a massive list of standards violations when running `phpcs`, it can be annoying to fix all the violations by hand. +Thankfully, PHP Code Sniffer is shipped with an automatic code fixer that can take care of the tedious task for you. +Here's the command to automatically fix the files you created/modified: + + $> phpcbf --standard=PSR2 + +If the command-line tools `diff` and `patch` are unavailabe for you, `phpcbf` can use slightly slower PHP equivalents by using the `--no-patch` argument. + ###Code documentation If you are interested in having the documentation of the Friendica code outside of the code files, you can use [Doxygen](http://doxygen.org) to generate it.