• Stars
    star
    129
  • Rank 278,435 (Top 6 %)
  • Language
    TypeScript
  • License
    BSD 3-Clause "New...
  • Created about 7 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Integrates phpfmt into VS Code

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 7.x 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

Key Type Description Default
phpfmt.php_bin string php executable path "php"
phpfmt.use_old_phpfmt boolean use old fmt.phar which supports 5.6 false
phpfmt.detect_indent boolean auto detecting indent type and size (will ignore indent_with_space) false
phpfmt.psr1 boolean activate PSR1 style false
phpfmt.psr1_naming boolean activate PSR1 style - Section 3 and 4.3 - Class and method names case. false
phpfmt.psr2 boolean activate PSR2 style true
phpfmt.wp boolean activate WP style false
phpfmt.indent_with_space integer | boolean use spaces instead of tabs for indentation. Default 4 4
phpfmt.enable_auto_align boolean enable auto align of ST_EQUAL and T_DOUBLE_ARROW false
phpfmt.visibility_order boolean fixes visibiliy order for method in classes - PSR-2 4.2 false
phpfmt.ignore array ignore file names whose names contain any pattern that could be matched with .match JS string method []
phpfmt.passes array call specific compiler pass []
phpfmt.exclude array disable specific passes []
phpfmt.smart_linebreak_after_curly boolean convert multistatement blocks into multiline blocks false
phpfmt.yoda boolean yoda-style comparisons false
phpfmt.cakephp boolean Apply CakePHP coding style false
phpfmt.custom_arguments string provide custom arguments to overwrite default arguments generated by config ""

Supported Transformations

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

Key Description
AddMissingParentheses Add extra parentheses in new instantiations.
AliasToMaster Replace function aliases to their masters - only basic syntax alias.
AlignConstVisibilityEquals Vertically align "=" of visibility and const blocks.
AlignDoubleArrow Vertically align T_DOUBLE_ARROW (=>).
AlignDoubleSlashComments Vertically align "//" comments.
AlignEquals Vertically align "=".
AlignGroupDoubleArrow Vertically align T_DOUBLE_ARROW (=>) by line groups.
AlignPHPCode Align PHP code within HTML block.
AlignTypehint Vertically align function type hints.
AllmanStyleBraces Transform all curly braces into Allman-style.
AutoPreincrement Automatically convert postincrement to preincrement.
AutoSemicolon Add semicolons in statements ends.
CakePHPStyle Applies CakePHP Coding Style
ClassToSelf "self" is preferred within class, trait or interface.
ClassToStatic "static" is preferred within class, trait or interface.
ConvertOpenTagWithEcho Convert from "<?=" to "<?php echo ".
DocBlockToComment Replace docblocks with regular comments when used in non structural elements.
DoubleToSingleQuote Convert from double to single quotes.
EchoToPrint Convert from T_ECHO to print.
EncapsulateNamespaces Encapsulate namespaces with curly braces
GeneratePHPDoc Automatically generates PHPDoc blocks
IndentTernaryConditions Applies indentation to ternary conditions.
JoinToImplode Replace implode() alias (join() -> implode()).
LeftWordWrap Word wrap at 80 columns - left justify.
LongArray Convert short to long arrays.
MergeElseIf Merge if with else.
SplitElseIf Merge if with else.
MergeNamespaceWithOpenTag Ensure there is no more than one linebreak before namespace
MildAutoPreincrement Automatically convert postincrement to preincrement. (Deprecated pass. Use AutoPreincrement instead).
NewLineBeforeReturn Add an empty line before T_RETURN.
OrganizeClass Organize class, interface and trait structure.
OrderAndRemoveUseClauses Order use block and remove unused imports.
OnlyOrderUseClauses Order use block - do not remove unused imports.
OrderMethod Organize class, interface and trait structure.
OrderMethodAndVisibility Organize class, interface and trait structure.
PHPDocTypesToFunctionTypehint Read variable types from PHPDoc blocks and add them in function signatures.
PrettyPrintDocBlocks Prettify Doc Blocks
PSR2EmptyFunction Merges in the same line of function header the body of empty functions.
PSR2MultilineFunctionParams Break function parameters into multiple lines.
ReindentAndAlignObjOps Align object operators.
ReindentSwitchBlocks Reindent one level deeper the content of switch blocks.
ReindentEnumBlocks Reindent one level deeper the content of enum blocks.
RemoveIncludeParentheses Remove parentheses from include declarations.
RemoveSemicolonAfterCurly Remove semicolon after closing curly brace.
RemoveUseLeadingSlash Remove leading slash in T_USE imports.
ReplaceBooleanAndOr Convert from "and"/"or" to "&&"/"
ReplaceIsNull Replace is_null($a) with null === $a.
RestoreComments Revert any formatting of comments content.
ReturnNull Simplify empty returns.
ShortArray Convert old array into new array. (array() -> [])
SmartLnAfterCurlyOpen Add line break when implicit curly block is added.
SortUseNameSpace Organize use clauses by length and alphabetic order.
SpaceAroundControlStructures Add space around control structures.
SpaceAroundExclamationMark Add spaces around exclamation mark.
SpaceBetweenMethods Put space between methods.
StrictBehavior Activate strict option in array_search, base64_decode, in_array, array_keys, mb_detect_encoding. Danger! This pass leads to behavior change.
StrictComparison All comparisons are converted to strict. Danger! This pass leads to behavior change.
StripExtraCommaInArray Remove trailing commas within array blocks
StripNewlineAfterClassOpen Strip empty lines after class opening curly brace.
StripNewlineAfterCurlyOpen Strip empty lines after opening curly brace.
StripNewlineWithinClassBody Strip empty lines after class opening curly brace.
StripSpaces Remove all empty spaces
StripSpaceWithinControlStructures Strip empty lines within control structures.
TightConcat Ensure string concatenation does not have spaces, except when close to numbers.
TrimSpaceBeforeSemicolon Remove empty lines before semi-colon.
UpgradeToPreg Upgrade ereg_* calls to preg_*
WordWrap Word wrap at 80 columns.
WrongConstructorName Update old constructor names into new ones. http://php.net/manual/en/language.oop5.decon.php
YodaComparisons Execute Yoda Comparisons.
SpaceAfterExclamationMark Add space after exclamation mark.
SpaceAroundParentheses Add 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

More Repositories

1

pixiv.moe

😘 A pinterest-style layout site, shows illusts on pixiv.net order by popularity.
TypeScript
361
star
2

typecho-plugin-Access

Access Log Plugin for Typecho
PHP
341
star
3

pixiv-api-php

Pixiv API for PHP
PHP
79
star
4

typecho-plugin-Parsedown

Typecho Parsedown 解析markdown插件
PHP
76
star
5

hitokoto

hitokoto本地源
PHP
52
star
6

kaomojify

👀 Convert Javascript code to Japanese kawaii kaomoji(かわいい顔文字).
JavaScript
26
star
7

typecho-plugin-BlockIP

Typecho IP黑名单插件
PHP
24
star
8

nssr

Node.js client for ShadowsocksR
TypeScript
15
star
9

typecho-plugin-HTMLCompress

Typecho HTMLCompress Plugin
PHP
13
star
10

Kotori.php

A Tiny Model-View-Controller(MVC) PHP Framework
PHP
12
star
11

pixiv-cookie

Promise-based pixiv cookie getter
JavaScript
11
star
12

typecho-plugin-ymplayer

A typecho plugin for ymplayer https://github.com/kirainmoe/ymplayer
PHP
10
star
13

honoka

Just a fetch() API wrapper for both Browser and Node.js.
JavaScript
9
star
14

android-webview-demo

Webview App for Android.
Java
9
star
15

typecho-theme-Twitter

A twitter liked typecho theme.
CSS
9
star
16

pixiv-ranking-new-tab

Show Pixiv daily rankings on your new tab page.
JavaScript
9
star
17

twitter-birthday

Parse out birthday info of twitter users.
PHP
8
star
18

posutoba

A Baidu-Tieba Liked Project.
PHP
8
star
19

moe-search

使用PHP编写的谷歌搜索代理程序>.<
CSS
8
star
20

Pixiv-LoveLive-Android

Pixiv LoveLive Viewer For Android
Java
7
star
21

OwO

顔文字を簡単に使える便利なツールです。
JavaScript
7
star
22

typecho-plugin-adminer

Adminer for Typecho Blog Platform
PHP
6
star
23

hosts2surge

Convert hosts file to Surge configuration
PHP
6
star
24

typecho-theme-Twentyfifteen

Typecho twentyfifteen theme from WordPress.
CSS
6
star
25

yarn-lock-cli

CLI tool for transforming registry in yarn.lock
TypeScript
5
star
26

typecho-theme-casper

Ghost official theme to Typecho
CSS
5
star
27

kaomojify-webpack-plugin

convert your built JavaScript code to Japanese kawaii kaomoji(かわいい顔文字)
JavaScript
4
star
28

bilibili-bv-to-av

Convert BV to av for bilibili.com
JavaScript
4
star
29

mpvue-diff-patch

JavaScript
3
star
30

private

Some Scripts and Config
JavaScript
3
star
31

tieba-notify

自动提醒贴吧消息的扩展程序
JavaScript
3
star
32

pcr.moe

HTML
3
star
33

segmentfault-notifier

Chrome扩展程序 SegmentFault 消息提醒
CSS
3
star
34

msxiaoice-php-api

PHP implement of yanwii/msxiaoiceapi
PHP
2
star
35

kiminonawa

君の名は。
JavaScript
2
star
36

eslint-config-kotori

ESLint shareable config for me.
JavaScript
2
star
37

layer-mobile

UMD build for layer
JavaScript
2
star
38

blog-site

Site for https://kotori.love
HTML
2
star
39

react-starter-template

A simple CLI for creating webpack + react + redux + ES6 starter apps
JavaScript
2
star
40

local-ip-webpack-plugin

Inject local ip address into webpack
JavaScript
2
star
41

float-calc

float calculator for javascript
JavaScript
2
star
42

vscode-i18n-hover

VSCode Extension for show i18n message on hover.
TypeScript
2
star
43

eslint-config-bmap

eslint config which helps to ignore Baidu Map SDK 's global variable
JavaScript
1
star
44

pixiv-downloader

CLI tool for downloading pixiv search results
JavaScript
1
star
45

kotori-webpack-plugin

kotori-webpack-plugin
JavaScript
1
star
46

image2data

Convert image to DataURI.
JavaScript
1
star
47

rule-snippets

JavaScript
1
star
48

suimin

JavaScript
1
star
49

Kotori.js

a rubbish javascript loader
JavaScript
1
star
50

twitter-cron

My twitter crons
PHP
1
star
51

docker-registry-proxy

Go
1
star
52

kotori-music-player

Chrome Extension
JavaScript
1
star