1.2.10 • Published 10 days ago

vscode-phpfmt v1.2.10

Weekly downloads
4
License
BSD-3-Clause
Repository
github
Last release
10 days ago

phpfmt for Visual Studio Code

Version Visual Studio Marketplace

The missing phpfmt extension for Visual Studio Code.

Installation

Open command palette F1 and select Extensions: Install Extension, then search for phpfmt.

Note: PHP 5.6 or newer is required in the machine to run this plugin.

Usage

F1 -> phpfmt: Format This File

or keyboard shortcut Ctrl + Shift + I which is Visual Studio Code default formatter shortcut

or right mouse context menu Format Document or Format Selection

Format On Save

Respects editor.formatOnSave setting.

You can turn off format-on-save on a per-language basis by scoping the setting:

// Set the default
"editor.formatOnSave": false,
// Enable per-language
"[php]": {
  "editor.formatOnSave": true
}

Q&A

Q: How to use phpfmt.php_bin with spaces such as C:\Program Files\php\php.exe ?
A: Wrap your path with quotes like:

{
  "phpfmt.php_bin": "\"C:\\Program Files\\php\\php.exe\""
}

It is recommended to add the directory of the php.exe to the PATH environment variable on Windows.
If it still not working, refer to #1 and Stack Overflow Related.

Q: How use tabs instead of spaces with PSR2 enabled ?
A: For PSR2, code MUST use 4 spaces for indenting, not tabs. But if you like PSR2, and do not like 4 spaces for indentation, add following configuration:

{
  "phpfmt.passes": [
    "PSR2KeywordsLowerCase",
    "PSR2LnAfterNamespace",
    "PSR2CurlyOpenNextLine",
    "PSR2ModifierVisibilityStaticOrder",
    "PSR2SingleEmptyLineAndStripClosingTag",
    "ReindentSwitchBlocks"
  ],
  "phpfmt.exclude": [
    "ReindentComments",
    "StripNewlineWithinClassBody"
  ],
  "phpfmt.psr2": false
}

Q: Is fmt.phar (phpfmt itself) still maintained ?
A: Since phpfmt has no maintainers, only Serious bugs will be fixed.
A: We now use fmt.stub.php from driade's phpfmt8 which is very updated.

Configuration

KeyTypeDescriptionDefault
phpfmt.php_binstringphp executable path"php"
phpfmt.use_old_phpfmtbooleanuse old fmt.phar which supports 5.6false
phpfmt.detect_indentbooleanauto detecting indent type and size (will ignore indent_with_space)false
phpfmt.psr1booleanactivate PSR1 stylefalse
phpfmt.psr1_namingbooleanactivate PSR1 style - Section 3 and 4.3 - Class and method names case.false
phpfmt.psr2booleanactivate PSR2 styletrue
phpfmt.wpbooleanactivate WP stylefalse
phpfmt.indent_with_spaceinteger \| booleanuse spaces instead of tabs for indentation. Default 44
phpfmt.enable_auto_alignbooleanenable auto align of ST_EQUAL and T_DOUBLE_ARROWfalse
phpfmt.visibility_orderbooleanfixes visibiliy order for method in classes - PSR-2 4.2false
phpfmt.ignorearrayignore file names whose names contain any pattern that could be matched with .match JS string method[]
phpfmt.passesarraycall specific compiler pass[]
phpfmt.excludearraydisable specific passes[]
phpfmt.smart_linebreak_after_curlybooleanconvert multistatement blocks into multiline blocksfalse
phpfmt.yodabooleanyoda-style comparisonsfalse
phpfmt.cakephpbooleanApply CakePHP coding stylefalse
phpfmt.custom_argumentsstringprovide custom arguments to overwrite default arguments generated by config""

Supported Transformations

F1 -> phpfmt: List Transformations to get the example of each transformation.

KeyDescription
SmartLnAfterCurlyOpenAdd line break when implicit curly block is added.
AddMissingParenthesesAdd 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 (=>).
AlignDoubleSlashCommentsVertically align "//" comments.
AlignEqualsVertically align "=".
AlignGroupDoubleArrowVertically align T_DOUBLE_ARROW (=>) 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 Style
ClassToSelf"self" is preferred within class, trait or interface.
ClassToStatic"static" is preferred within class, trait or interface.
ConvertOpenTagWithEchoConvert from "<?=" to "<?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 braces
GeneratePHPDocAutomatically generates PHPDoc blocks
IndentTernaryConditionsApplies indentation to ternary conditions.
JoinToImplodeReplace implode() alias (join() -> 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 namespace
MildAutoPreincrementAutomatically 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 Blocks
PSR2EmptyFunctionMerges 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.
ReindentEnumBlocksReindent one level deeper the content of enum blocks.
RemoveIncludeParenthesesRemove parentheses from include declarations.
RemoveSemicolonAfterCurlyRemove semicolon after closing curly brace.
RemoveUseLeadingSlashRemove leading slash in T_USE imports.
ReplaceBooleanAndOrConvert from "and"/"or" to "&&"/"". Danger! This pass leads to behavior change.
ReplaceIsNullReplace is_null($a) with null === $a.
RestoreCommentsRevert any formatting of comments content.
ReturnNullSimplify empty returns.
ShortArrayConvert old array into new array. (array() -> [])
SortUseNameSpaceOrganize use clauses by length and alphabetic order.
SpaceAroundControlStructuresAdd space around control structures.
SpaceAroundExclamationMarkAdd spaces around exclamation mark.
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 blocks
StripNewlineAfterClassOpenStrip 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 spaces
StripSpaceWithinControlStructuresStrip 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. http://php.net/manual/en/language.oop5.decon.php
YodaComparisonsExecute Yoda Comparisons.
SpaceAfterExclamationMarkAdd space after exclamation mark.
SpaceAroundParenthesesAdd spaces inside parentheses.

Contribute

Running extension

  • Open this repository inside Visual Studio Code
  • Debug sidebar
  • Launch Extension

Running tests

  • Open this repository inside Visual Studio Code
  • Debug sidebar
  • Launch Tests
1.2.10

10 days ago

1.2.8

12 days ago

1.2.7

12 days ago

1.2.6

12 days ago

1.2.5

12 days ago

1.2.4

12 days ago

1.2.3

12 days ago

1.2.2

12 days ago

1.2.9

12 days ago

1.2.0

17 days ago

1.2.1

17 days ago

1.1.40

17 days ago

1.1.39

1 month ago

1.1.38

2 months ago

1.1.37

2 months ago

1.1.36

4 months ago

1.1.35

5 months ago

1.1.29

6 months ago

1.1.28

6 months ago

1.1.30

6 months ago

1.1.34

6 months ago

1.1.33

6 months ago

1.1.32

6 months ago

1.1.31

6 months ago

1.1.27

6 months ago

1.1.26

6 months ago

1.1.25

6 months ago

1.1.12

9 months ago

1.1.11

10 months ago

1.1.10

10 months ago

1.1.16

8 months ago

1.1.15

8 months ago

1.1.14

8 months ago

1.1.13

8 months ago

1.1.19

8 months ago

1.1.18

8 months ago

1.1.17

8 months ago

1.1.23

7 months ago

1.1.22

8 months ago

1.1.21

8 months ago

1.1.20

8 months ago

1.1.24

7 months ago

1.1.1

1 year ago

1.1.9

12 months ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.30

6 years ago

1.0.29

6 years ago

1.0.28

6 years ago

1.0.27

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago