<commit_before># PHP Formatter

After installing as an extension with Visual Studio Code, this extension automatically formats your PHP code, in accordance with PSR-0, PSR-1, [PSR-2](http://www.php-fig.org/psr/psr-2/) or Symfony style conventions.

![GIF example of formatting your PHP code](images/fix-example.gif?raw=true "Example of formatting your PHP code")

## Features

* Format current selection only, or the whole file.
* Trigger formatting with custom keybindings or actions.
* Supports formatting on save.
* Supports different PHP-CS-Fixer installation methods, i.e. Composer vs manual installation.
* Supports level and fixers.
* Can be configured to support other file extensions than PHP as well, i.e. ".inc" files.

## Requirements

Requires installation of the PHP-CS-Fixer. For more info see [their repo](https://github.com/FriendsOfPHP/PHP-CS-Fixer#installation).

## Installation Guide

1. Download this extension by using any of the methods [here](https://code.visualstudio.com/Docs/extensions/install-extension).
2. Install PHP-CS-Fixer using one of the methods [here](https://github.com/FriendsOfPHP/PHP-CS-Fixer#installation).
3. Based on your installation method of PHP-CS-Fixer, use one of the following settings:

   ---

   ### **With Composer**

   Add Composer to your PATH environment variable. E.g. on Windows: `%APPDATA%\Composer\vendor\bin`. E.g. on Linux: `/.composer/vendor/bin`.

   Add `"phpformatter.composer": true` to your VSCode user settings.

   ![VSCode user settings result with Composer](images/install-composer.jpg?raw=true "VSCode user settings result with Composer")

   ---

   ### **Manual**

   Add PHP to your PATH environment variable. I.e. ensure that `php -v` works. Otherwise use `"phpformatter.phpPath" = "/path/to/php/executable"`.

   Point the `phpformatter.pharPath` setting to where you put the php-cs-fixer file.

   ![VSCode user settings result with Manual](images/install-manual.jpg?raw=true "VSCode user settings result with Manual")

   *Not working?* Make sure the `phpformatter.composer` setting is set to `false`, which it is by default.

   ---

4. To format a file with a custom keybinding or action, see [Extension Commands](#commands).
~~To format a file on save, add this to your [user settings](https://code.visualstudio.com/Docs/customization/userandworkspace): `"phpformatter.onSave" = true`~~ Awaiting VSCode feature to support this functionality.
5. You're done! You might need to restart Visual Studio Code, however.

## Extension Settings

This extension contributes the following settings:

* `phpformatter.pharPath`: Should point to php-cs-fixer.phar file, if you have installed this manually (without Composer). Should include .phar extension.
* `phpformatter.phpPath`: If the pharPath is set, and you are not using Composer, this should point to the php.exe file.
* `phpformatter.composer`: Whether the php-cs-fixer library has been installed using Composer. If true, the extension will override pharPath and assume you have added Composer to your PATH.
* `phpformatter.onSave`: ~~Whether files should be fixed on save.~~ Not supported right now. Awaiting an [internal VSCode feature](https://github.com/Microsoft/vscode/issues/239). Use [the phpformatter.fix command](#commands) for now instead.
* `phpformatter.level`: Fixer level to use when fixing a file, e.g. psr0, psr1, psr2, symfony ([More info](https://github.com/FriendsOfPHP/PHP-CS-Fixer#usage)).
* `phpformatter.fixers`: Fixers to use when fixing a file, e.g. strict, short_array_syntax ([More info](https://github.com/FriendsOfPHP/PHP-CS-Fixer#usage)).
* `phpformatter.additionalExtensions`: Which additional file extensions, besides PHP, should be fixed as well. E.g. inc, without the leading dot. For this to work you'll also have to configure your VSCode files.associations settings ([More info](https://code.visualstudio.com/Docs/languages/overview#_common-questions)).
* `phpformatter.logging`: If true, the extension will log all sorts of (debug) info to the console. Useful for troubleshooting.
* `phpformatter.notifications`: If true, the extension will show notifications.

## <a name="commands"></a>Extension commands

The extension currently contributes just one command. Your Visual Studio Code environment can be configured to trigger this command with a custom keybinding or other action.

### phpformatter.fix

* Fixes the current file, or selection, if there is any.
* Does not save the file after fixing.

To set this up. Go to `File -> Preferences -> Keyboard Shortcuts` and add the following to `keybindings.json`:

`{"key": "alt+shift+f", "command": "phpformatter.fix", "when": "editorFocus"}`

After saving the file you should be able to format files using the keybinding `alt+shift+f`.

## Known Issues

* If you add Composer to your PATH, make sure to restart ALL of your Visual Studio Code instances afterwards. Visual Studio Code only reads out PATH variables during startup.
* If you are on Windows, using xampp, and get the error `PHP Warning: PHP Startup: Unable to load dynamic library`, try going to you xampp directory and run `setup_xampp.bat`. After that, restart Visual Studio Code and try again.

**Note:** Most issues stem from incorrect installation of the PHP-CS-Fixer, see [their repo](https://github.com/FriendsOfPHP/PHP-CS-Fixer#installation) for more info.

## Release Notes

### 0.2.0

* Migrated the code to TypeScript!
* Temp files are now the way to go by default, switching back is no longer supported. Therefore, the `phpformatter.useTempFiles` setting got removed.
* Deprecated `phpformatter.enableFixerLogging` setting got removed in favor of `phpformatter.logging`.
* The extension is now categorized as Formatter on the Marketplace.

### 0.1.3

* Disabled onSave command until VSCode supports preSave event.
* Improved Readme.

### 0.1.2

Solved an issue where fixing a file would erase its contents.

### 0.1.1

New icon.

### 0.1.0

* Added `phpformatter.useTempFiles` setting, which is on by default. This fixes a whole ranges of issues the old method had, and opens up the road other features as well.
* Added `phpformatter.fix` command. This introduces the ability to fix a file or selection by registering a custom keybinding. See [Extension Commands](#commands) for more info.
* Added the ability to fix only the current selection. This requires `phpformatter.useTempFiles` to be turned on.
* Deprecated `phpformatter.enableFixerLogging` in favor of `phpformatter.logging`.
* Added `phpformatter.logging` setting to replace `phpformatter.enableFixerLogging`.
* Improved logging. Added more log messages and added two notifications.

### 0.0.7

* Added `phpformatter.notifications` setting.
* The extension will now show a notification when the required settings are not set.
* The notification has a button that opens up a browser with the installation guide on the Github page.
* Added installation guide and known issue to the readme.

### 0.0.6

Added icon and more meta info in package.json. As well as the first icon!

### 0.0.5

Added working support for multiple file extensions besides .php. See `phpformatter.additionalExtensions` setting for more info.

### 0.0.4

All paths now support spaces (`' '`).

### 0.0.3

Setting `phpformatter.composer` to `true` now actually overrides the use of pharPath.

### 0.0.2

* Code improvements.
* Fixed functionality.
* Improved code readability.
* Added setting to enable fixer logging. Logs all fixer results (including errors) to the console.
* Settings are now read every time the fix function is called. Previously settings were only read during activation.

### 0.0.1

Initial commit.<commit_msg>Cleaned up readme. Moved info to wiki on GitHub.<commit_after># PHP Formatter

After installing as an extension with Visual Studio Code, this extension automatically formats your PHP code, in accordance with PSR-0, PSR-1, [PSR-2](http://www.php-fig.org/psr/psr-2/) or Symfony style conventions.

![GIF example of formatting your PHP code](images/fix-example.gif?raw=true "Example of formatting your PHP code")

## Features

* Format current selection only, or the whole file.
* Trigger formatting with custom keybindings or actions.
* Supports formatting on save.
* Supports level and fixers.
* Can be configured to support other file extensions than PHP as well, i.e. ".inc" files.
* Supports different PHP-CS-Fixer installation methods, i.e. Composer vs manual installation.

## Setup

Refer to our [wiki](https://github.com/Dickurt/vscode-php-formatter/wiki) for a quick and easy guide on how to install the extension and its dependencies.

## Configuration

Want custom [keybindings](https://github.com/Dickurt/vscode-php-formatter/wiki/Extension-Commands)? Need specific [levels and fixers](https://github.com/Dickurt/vscode-php-formatter/wiki/Extension-Settings)? Check our [wiki](https://github.com/Dickurt/vscode-php-formatter/wiki)
{'fraction_non_alphanumeric': 0.09583192899674194, 'fraction_numerical': 0.0061790810021345914, 'mean_word_length': 4.51548946716233, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 13, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2665995', 'n_tokens_mistral': 2603, 'n_tokens_neox': 2454, 'n_words': 1066}