[分享]格式化php代码工具phpCodeBeautifier(phpCB)设置参数配置说明

2017-03-06PHP3890

格式化php代码工具phpCodeBeautifier(phpCB)设置参数配置说明,php美化工具。phpCodeBeautifier原官方网站已经挂了。找了好久才找到这个,这个也是不全的,算是做参考吧。底部有一个我自己现在用的参数配置。

phpCodeBeautifier, 又简称为phpCB,是一款命令行下的php代码格式化工具,能够有是你的php代码变得更加地漂亮。而且phpCodeBeautifier提供非常多的设置参数,用户可以根据个人要求得到想要的格式化结果。

QQ图片20170313150414.png

命令行代码格式:

phpCB.exe [参数] [原php文件路径]

下面是phpCodeBeautifier(phpCB)参数配置说明:

  • –space-after-start-bracket: 在左括号中插入一个空格。

    加入 参数 –space-after-start-bracket 将显示:没加 –space-after-start-bracket
    <?php
    
    if ( $condition) {
    }
    
    ?>
    <?php
    
    if ($condition) {
    } 
    
    ?>
  • –space-before-end-bracket: 在右括号插入一个空格。

    加 –space-before-end-bracket不加 –space-before-end-bracket
    <?php
    
    if ($condition ) {
    } 
    
    ?>
    <?php
    
    if ($condition) {
    } 
    
    ?>
  • –space-after-if: 在 if 插入一个空格。

    加 –space-after-if不加 –space-after-if
    <?php
    
    if ($condition) {
    } 
    
    ?>
    <?php
    
    if($condition) {
    } 
    
    ?>
  • –space-after-switch: 在 switch 后插入一个空格。

    加 –space-after-switch不加 –space-after-switch
    <?php
    
    switch ($condition) {
    } 
    
    ?>
    <?php
    
    switch($condition) {
    } 
    
    ?>
  • –space-after-while: 在 while 后插入一个空格.

    加 –space-after-while不加–space-after-while
    <?php
    
    while ($condition) {
    } 
    
    ?>
    <?php
    
    while($condition) {
    } 
    
    ?>
  • –space-before-start-angle-bracket: 在左边大括号插入一个空格。

    加 –space-before-start-angle-bracket不加 –space-before-start-angle-bracket
    <?php
    
    while($condition) {
    } 
    
    ?>
    <?php
    
    while($condition){
    } 
    
    ?>
  • –space-after-end-angle-bracket: 在右边大括号插入一个空格。

    加 –space-after-end-angle-bracket不加 –space-after-end-angle-bracket
    <?php
    
    while($condition){
    } // end of while
    
    ?>
    <?php
    
    while($condition){
    }// end of while
    
    ?>
  • –extra-padding-for-case-statement: case 语句块使用缩进.

    加 –extra-padding-for-case-statement不加 –extra-padding-for-case-statement
    <?php
    
    switch($condition){
        case 1:
            action1();
            break;
        case 2:
            action2();
            break;
        default:
            defaultaction();
            break;
    }
    
    ?>
    <?php
    
    switch($condition){
    case 1:
        action1();
        break;
    case 2:
        action2();
        break;
    default:
        defaultaction();
        break;
    }
    
    ?>
  • –one-true-brace-function-declaration: 函数定义时两个大括号对齐.

    加 –one-true-brace-function-declaration不加 –one-true-brace-function-declaration
    <?php
    
    function aFunction($param)
    {
        // function content
    }
    
    ?>
    <?php
    
    function aFunction($param) {
        // function content
    }
    
    ?>
  • –glue-amperscore: & 引用符号紧贴着变量.

    加 –glue-amperscore不加 –glue-amperscore
    <?php
    
    $value = &$objectInstance;
    
    ?>
    <?php
    
    $value = & $objectInstance;
    
    ?>
  • –change-shell-comment-to-double-slashes-comment: 将 # 标记的注释转换成 // 的

    原来的样式加 –change-shell-comment-to-double-slashes-comment不加 –change-shell-comment-to-double-slashes-comment
    <?php
    
    #comment content
    //another comment
    
    ?>
    <?php
    
    // comment content
    // another comment
    
    ?>
    <?php
    
    # comment content
    // another comment
    
    ?>
  • –indent-with-tab: If selected, tabulation (ASCII #9) character is used to indent text, elsewhere space (ASCII #32) character is used.

  • –force-large-php-code-tag: 将 <? ?> 和 <% %> 标记转换成 <?php ?> 标记.

    原来的代码样式加 –force-large-php-code-tag不加 –force-large-php-code-tag
    <?
    
    ?>
    
    <%
    
    %>
    <?php
    
    ?>
    
    <?php
    
    ?>
    <?
    
    ?>
    
    <%
    
    %>
  • –force-true-false-null-contant-lowercase: 将 TRUE, FALSE, NULL 转换成小写的

    原来的代码样式加 –force-true-false-null-contant-lowercase不加 –force-true-false-null-contant-lowercase
    <?php
    
    if(TRUE){
        if(FALSE){
            $value = NULL;
        }
    }
    
    ?>
    <?php
    
    if(true){
        if(false){
            $value = null;
        }
    }
    
    ?>
    <?php
    
    if(TRUE){
        if(FALSE){
            $value = NULL;
        }
    }
    
    ?>
  • –align-equal-statements: 等号对齐.

  • 原来的代码样式加 –align-equal-statements
    <?php
    
    $noError = true;
    $feildEmpty = false;
    $showMessage = false;
    $showMessage = false; 
    
    $anotherVariable[0123] = \'bla bla bla\';
    
    $showBlaBlaBlaMessage = false; 
    
    ?>
    <?php
    $noError               = true;
    $feildEmpty            = false;
    $showMessage           = false;
    $showMessage           = false;
    $anotherVariable[0123] = \'bla bla bla\';
    $showBlaBlaBlaMessage  = false; 
    
    ?>
  • –align-equal-statements-to-fixed-pos: 将所有等号在指定位置对齐.

    不加加 –align-equal-statements-to-fixed-pos 30
    <?php
    
    $noError = true;
    $feildEmpty = false;
    $showMessage = false;
    $showMessage = false; 
    
    $anotherVariable[0123] = \'bla bla bla\';
    
    $showBlaBlaBlaMessage = false; 
    
    ?>
    <?php
    $noError                     = true;
    $feildEmpty                  = false;
    $showMessage                 = false;
    $showMessage                 = false;
    $anotherVariable[0123]       = \'bla bla bla\';
    $showBlaBlaBlaMessage        = false; 
    
    ?>
  • 代码注释风格:

    –comment-rendering-style PEAR 风格–comment-rendering-style PHPDoc 风格
    <?php
    
    /**
     * bla bla bla
     *
     * @access public
     */
    
    ?>
    <?php
    
    /**
    * bla bla bla
    *
    * @access public
    */
    
    ?>

提供一个经典C代码风格的配置参数:

–space-after-if –optimize-eol –space-after-switch –space-after-while –space-before-start-angle-bracket –space-after-end-angle-bracket –extra-padding-for-case-statement –glue-amperscore –change-shell-comment-to-double-slashes-comment –indent-with-tab –force-large-php-code-tag –force-true-false-null-contant-lowercase –comment-rendering-style PEAR –equal-align-position 50 –padding-char-count 1 “$(FilePath)”

再提供一个我自己经常用的代码风格的配置参数:(批处理bat调用phpCB.exe)

"phpCB.exe" --space-after-if --glue-arrow --optimize-eol --space-after-switch --space-after-while --space-before-start-angle-bracket --space-after-end-angle-bracket --extra-padding-for-case-statement --glue-amperscore --change-shell-comment-to-double-slashes-comment --force-large-php-code-tag --force-true-false-null-contant-lowercase --comment-rendering-style PEAR --align-equal-statements --padding-char-count 4 "%filename%">"phpCB.tmp"

更新日志

2007-02-15 - Version 1.0.1

- Fixed incorrect handling of options issue

2007-02-15 - Version 1.0

- Linux ready

2003-09-18 - Version 0.8

- Bug #1859: Format of method reference wrong
         - Bug #1943: skip formatting
         - Bug #1329: no need to use 'cbo' prefix in user interface
         - Bug #1387: Having added a new Profile Code beautifier refuses to run at all
         - Bug #1342: indenting does wrong with if ($$...)
         - Bug #1391: Required library was not found: rtl60.bpl
         - Bug #1397: Loop on configuration request
         - Bug #1737: Bug link
         - Bug #1395: CTRL+D in PHPEdit doubles new lines
         - Bug #1336: The place of the braces
         - Bug #1736: If inside Switch not well beautified
         - Bug #1363: XML tag badly handled
         - Bug #1360: option to only rewrite PHPDoc's comment

2003-01-07 - Version 0.7.7

+ #1062 Added cboRewriteOnlyDocumentationComment option in the code beautifier.
         + Added cboOneTrueBrace in the code beautifier
         - Fixed bug #1054: If /Else indentation
         - Fixed bug #1054: do {} while is not correct indented
         - Fixed bug #971: PHP Interpreter line command modified

2002-12-26 - Version 0.7.6

- Fixed bug #1146: Tick `` code is removed.

2002-12-02 - Version 0.7.5

- Fixed bug #1105: Command line exe (phpcb.exe) does not support --optimize-eol

2002-11-03 - Version 0.7.4

- Fixed problem with if inside switchs

2002-10-01 - Version 0.7.3

+ Added --glue-arrow option to strip spaces bfore and after ->
         (or to add one if option is not available)
         + Added --remove-comments option to remove all comments from the processed file.
         + Added --optimize-eol which strip all useless lines
         (>1 consecutive line end is changed into a single EOL)

2002-09-14 - Version 0.7.2

+ Added support for multiple configuration files.
         - Fixed bug #744
         - Fixed bug #741
         - Fixed bug #740
         - Fixed bug #742
         - Fixed bug #626

2002-09-13

+ Added file format support.
         ~ The progress bar is now hidden when the code beautifier is inactive.

2002-08-04 - Version 0.7.1

+ Added the ability to drop files to open them.
         + Added scrolling synchronization between both Before & After form.

  • 相关文章
  • 查看评论:(0)
【已经有0位大神发现了看法】

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

分享:

支付宝

微信