phpCB: PHP Code Beautifier

Summary

php Code Beautifier

phpCodeBeautifier is Copyright © 2002-2004 Sébastien Hordeaux and Copyright © 2004-2007 WaterProof SARL. Contact us before including it in any package (commercial or not).

The main goal of this tool is to avoid spending hours on reformating code to suit my own way of presenting it. The tool has been declined into 3 versions:

  1. A GUI version which allow to process file visually.
  2. A command line version which allow to be batched or integrated with other tools (CVS, IDE, ...)
  3. As an integrated tool of PHPEdit.

I hope this tool will assist you as it does for me. If you find bug, please feel free to report them in the issue tracker.

This tool has required work; you are encouraged to reward this work by making a donation, this is the only way to encourage us to continue developping tools like this one and keeping them free.

Check http://www.waterproof.fr/products/phpCodeBeautifier/ for last updates. ChangLog is available from here. Current version is 1.0. You can download it here.

Usage

Command line syntax is the following:

phpCB.exe [options] [filename]

Where options is from the previous topic list and srcFile is the file to beautify. If no srcFile is given, standard input will be used. The transformed text will be outputted to standard output, you can redirect it to a file using the > symbol.

The following options are available:

Comment rendering style

The following style of comment formating are available:

--comment-rendering-style PEAR --comment-rendering-style PHPDoc
<?php

/**
 * bla bla bla
 *
 * @access public
 */

?>
<?php

/**
* bla bla bla
*
* @access public
*/

?>

PEAR Coding standards Tips

To follow PEAR coding standards, I recommend you to use the following configuration:

Option State
--space-after-start-bracket-
--space-before-end-bracket-
--space-after-ifX
--space-after-switchX
--space-after-whileX
--space-before-start-angle-bracketX
--space-after-end-angle-bracketX
--extra-padding-for-case-statement-
--one-true-brace-function-declarationX
--glue-amperscoreX
--change-shell-comment-to-double-slashes-commentX
--indent-with-tab-
--force-large-php-code-tagX
--force-true-false-null-contant-lowercaseX
--align-equal-statementsX
--align-equal-statements-to-fixed-pos-

Use 4 for the padding character count to use.

Example

This is a sample call of the command line version:

# phpCB --space-after-if                             \
    --space-after-switch                             \
    --space-after-while                              \
    --space-before-start-angle-bracket               \
    --space-after-end-angle-bracket                  \
    --one-true-brace-function-declaration            \
    --glue-amperscore                                \
    --change-shell-comment-to-double-slashes-comment \
    --force-large-php-code-tag                       \
    --force-true-false-null-contant-lowercase        \
    --align-equal-statements                         \
    --comment-rendering-style PEAR                   \
    --equal-align-position 50                        \
    --padding-char-count 4                           \
    c:\some\path\to\file.php