PHPackages                             phpfmt-next/fmt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. phpfmt-next/fmt

AbandonedApplication[Utility &amp; Helpers](/categories/utility)

phpfmt-next/fmt
===============

A script to automatically fix K&amp;R and PSR-1/2 Coding Standard.

321971[4 issues](https://github.com/kokororin/fmt/issues)[2 PRs](https://github.com/kokororin/fmt/pulls)PHP

Pushed 4y ago2 watchersCompare

[ Source](https://github.com/kokororin/fmt)[ Packagist](https://packagist.org/packages/phpfmt-next/fmt)[ RSS](/packages/phpfmt-next-fmt/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersionsUsed By (0)

phpfmt
======

[](#phpfmt)

Requirements
------------

[](#requirements)

- PHP &gt;= 5.6.0 to run the formatter. Note that the formatter can parse even a PHP file version 4 in case needed. HHVM is not supported.

Usage
-----

[](#usage)

```
$ php fmt.phar filename.php
```

```
$ php fmt.phar --help
Usage: fmt.phar [-hv] [-o=FILENAME] [--config=FILENAME] [--cache[=FILENAME]] [options]
  --align_double_arrow              enable auto align of T_DOUBLE_ARROW
  --align_equals                    enable auto align of ST_EQUAL
  --cache[=FILENAME]                cache file. Default: .php.tools.cache
  --cakephp                         Apply CakePHP coding style
  --config=FILENAME                 configuration file. Default: .phpfmt.ini
  --constructor=type                analyse classes for attributes and generate constructor - camel, snake, golang
  --dry-run                         Runs the formatter without actually changing files; returns exit code 1 if changes would have been applied
  --enable_auto_align               enable auto align of ST_EQUAL and T_DOUBLE_ARROW
  --exclude=pass1,passN,...         disable specific passes
  --help-pass                       show specific information for one pass
  --ignore=PATTERN-1,PATTERN-N,...  ignore file names whose names contain any PATTERN-N
  --indent_with_space=SIZE          use spaces instead of tabs for indentation. Default 4
  --lint-before                     lint files before pretty printing (PHP must be declared in %PATH%/$PATH)
  --list                            list possible transformations
  --list-simple                     list possible transformations - greppable
  --no-backup                       no backup file (original.php~)
  --passes=pass1,passN,...          call specific compiler pass
  --profile=NAME                    use one of profiles present in configuration file
  --psr                             activate PSR1 and PSR2 styles
  --psr1                            activate PSR1 style
  --psr1-naming                     activate PSR1 style - Section 3 and 4.3 - Class and method names case.
  --psr2                            activate PSR2 style
  --selfupdate                      self-update fmt.phar from Kotori API
  --setters_and_getters=type        analyse classes for attributes and generate setters and getters - camel, snake, golang
  --smart_linebreak_after_curly     convert multistatement blocks into multiline blocks
  --version                         version
  --visibility_order                fixes visibiliy order for method in classes - PSR-2 4.2
  --yoda                            yoda-style comparisons
  -h, --help                        this help message
  -o=-                              output the formatted code to standard output
  -o=file                           output the formatted code to "file"
  -v                                verbose

If  is "-", it reads from stdin
```

Supported Transformations
-------------------------

[](#supported-transformations)

KeyDescriptionAddMissingParenthesesAdd extra parentheses in new instantiations.AliasToMasterReplace function aliases to their masters - only basic syntax alias.AlignConstVisibilityEqualsVertically align "=" of visibility and const blocks.AlignDoubleArrowVertically align T\_DOUBLE\_ARROW (=&gt;).AlignDoubleSlashCommentsVertically align "//" comments.AlignEqualsVertically align "=".AlignGroupDoubleArrowVertically align T\_DOUBLE\_ARROW (=&gt;) by line groups.AlignPHPCodeAlign PHP code within HTML block.AlignTypehintVertically align function type hints.AllmanStyleBracesTransform all curly braces into Allman-style.AutoPreincrementAutomatically convert postincrement to preincrement.AutoSemicolonAdd semicolons in statements ends.CakePHPStyleApplies CakePHP Coding StyleClassToSelf"self" is preferred within class, trait or interface.ClassToStatic"static" is preferred within class, trait or interface.ConvertOpenTagWithEchoConvert from "&lt;?=" to "&lt;?php echo ".DocBlockToCommentReplace docblocks with regular comments when used in non structural elements.DoubleToSingleQuoteConvert from double to single quotes.EchoToPrintConvert from T\_ECHO to print.EncapsulateNamespacesEncapsulate namespaces with curly bracesGeneratePHPDocAutomatically generates PHPDoc blocksIndentTernaryConditionsApplies indentation to ternary conditions.JoinToImplodeReplace implode() alias (join() -&gt; implode()).LeftWordWrapWord wrap at 80 columns - left justify.LongArrayConvert short to long arrays.MergeElseIfMerge if with else.SplitElseIfMerge if with else.MergeNamespaceWithOpenTagEnsure there is no more than one linebreak before namespaceMildAutoPreincrementAutomatically convert postincrement to preincrement. (Deprecated pass. Use AutoPreincrement instead).NewLineBeforeReturnAdd an empty line before T\_RETURN.OrganizeClassOrganize class, interface and trait structure.OrderAndRemoveUseClausesOrder use block and remove unused imports.OnlyOrderUseClausesOrder use block - do not remove unused imports.OrderMethodOrganize class, interface and trait structure.OrderMethodAndVisibilityOrganize class, interface and trait structure.PHPDocTypesToFunctionTypehintRead variable types from PHPDoc blocks and add them in function signatures.PrettyPrintDocBlocksPrettify Doc BlocksPSR2EmptyFunctionMerges in the same line of function header the body of empty functions.PSR2MultilineFunctionParamsBreak function parameters into multiple lines.ReindentAndAlignObjOpsAlign object operators.ReindentSwitchBlocksReindent one level deeper the content of switch blocks.RemoveIncludeParenthesesRemove parentheses from include declarations.RemoveSemicolonAfterCurlyRemove semicolon after closing curly brace.RemoveUseLeadingSlashRemove leading slash in T\_USE imports.ReplaceBooleanAndOrConvert from "and"/"or" to "&amp;&amp;"/"ReplaceIsNullReplace is\_null($a) with null === $a.RestoreCommentsRevert any formatting of comments content.ReturnNullSimplify empty returns.ShortArrayConvert old array into new array. (array() -&gt; \[\])SmartLnAfterCurlyOpenAdd line break when implicit curly block is added.SortUseNameSpaceOrganize use clauses by length and alphabetic order.SpaceAroundControlStructuresAdd space around control structures.SpaceAfterExclamationMarkAdd space after exclamation mark.SpaceAroundExclamationMarkAdd spaces around exclamation mark.SpaceAroundParenthesesAdd spaces inside parentheses.SpaceBetweenMethodsPut space between methods.StrictBehaviorActivate strict option in array\_search, base64\_decode, in\_array, array\_keys, mb\_detect\_encoding. Danger! This pass leads to behavior change.StrictComparisonAll comparisons are converted to strict. Danger! This pass leads to behavior change.StripExtraCommaInArrayRemove trailing commas within array blocksStripNewlineAfterClassOpenStrip empty lines after class opening curly brace.StripNewlineAfterCurlyOpenStrip empty lines after opening curly brace.StripNewlineWithinClassBodyStrip empty lines after class opening curly brace.StripSpacesRemove all empty spacesStripSpaceWithinControlStructuresStrip empty lines within control structures.TightConcatEnsure string concatenation does not have spaces, except when close to numbers.TrimSpaceBeforeSemicolonRemove empty lines before semi-colon.UpgradeToPregUpgrade ereg\_\* calls to preg\_\*WordWrapWord wrap at 80 columns.WrongConstructorNameUpdate old constructor names into new ones. YodaComparisonsExecute Yoda Comparisons.What does the Code Formatter do?
--------------------------------

[](#what-does-the-code-formatter-do)

### K&amp;R configuration

[](#kr-configuration)

BeforeAfter```
