0.0.5 • Published 2 years ago

coc-phpfmt v0.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

coc-phpfmt

phpfmt extension for coc.nvim. Forked from vscode-phpfmt

Install

:CocInstall coc-phpfmt

Commands

namedescription
phpfmt.listTransformationsphpfmt: List Transformations
phpfmt.openOutputphpfmt: Open Output

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.

Configuration

KeyTypeDescriptionDefault
phpfmt.php_binstringphp executable path"php"
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.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.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

KeyDescription
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.
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() -> [])
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 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.

License

MIT


This extension is built with create-coc-extension

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago