{"id":13448077,"url":"https://github.com/prettier/plugin-php","last_synced_at":"2025-05-14T07:08:19.866Z","repository":{"id":37851985,"uuid":"115235915","full_name":"prettier/plugin-php","owner":"prettier","description":"Prettier PHP Plugin","archived":false,"fork":false,"pushed_at":"2025-04-23T07:36:14.000Z","size":6226,"stargazers_count":1796,"open_issues_count":116,"forks_count":136,"subscribers_count":23,"default_branch":"main","last_synced_at":"2025-05-11T20:22:41.689Z","etag":null,"topics":["autoformat","beautifier","formatter","php","php5","php7","prettier","printer"],"latest_commit_sha":null,"homepage":"https://loilo.github.io/prettier-php-playground/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prettier.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"prettier","open_collective":"prettier","thanks_dev":"u/gh/prettier","tidelift":"npm/prettier"}},"created_at":"2017-12-24T02:56:22.000Z","updated_at":"2025-05-09T16:01:18.000Z","dependencies_parsed_at":"2023-10-13T05:54:13.591Z","dependency_job_id":"9b9aac5a-2dba-4560-be40-37426f644d56","html_url":"https://github.com/prettier/plugin-php","commit_stats":{"total_commits":1428,"total_committers":57,"mean_commits":25.05263157894737,"dds":0.6393557422969187,"last_synced_commit":"6f7d65d75773401705d2bc316ef9e0ea332cc6c5"},"previous_names":["prettier/prettier-php"],"tags_count":65,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prettier%2Fplugin-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prettier%2Fplugin-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prettier%2Fplugin-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prettier%2Fplugin-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prettier","download_url":"https://codeload.github.com/prettier/plugin-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253997104,"owners_count":21996802,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autoformat","beautifier","formatter","php","php5","php7","prettier","printer"],"created_at":"2024-07-31T05:01:34.881Z","updated_at":"2025-05-14T07:08:19.849Z","avatar_url":"https://github.com/prettier.png","language":"PHP","readme":"\u003cdiv align=\"center\"\u003e\n\u003cimg alt=\"Prettier\"\n  src=\"https://raw.githubusercontent.com/prettier/prettier-logo/master/images/prettier-icon-light.png\"\u003e\n\u003cimg alt=\"PHP\" height=\"180\" hspace=\"25\" vspace=\"15\"\n  src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/PHP-logo.svg/500px-PHP-logo.svg.png\"\u003e\n\u003c/div\u003e\n\n\u003ch2 align=\"center\"\u003ePrettier PHP Plugin\u003c/h2\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/prettier/plugin-php/actions\"\u003e\n    \u003cimg alt=\"GitHub Workflow Status\" src=\"https://img.shields.io/github/workflow/status/prettier/plugin-php/Node CI?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@prettier/plugin-php\"\u003e\n    \u003cimg alt=\"npm version\" src=\"https://img.shields.io/npm/v/@prettier/plugin-php.svg?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/prettier/plugin-php\"\u003e\n    \u003cimg alt=\"Codecov Coverage Status\" src=\"https://img.shields.io/codecov/c/github/prettier/plugin-php.svg?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003c!-- \u003ca href=\"https://www.npmjs.com/package/@prettier/plugin-php\"\u003e\n    \u003cimg alt=\"monthly downloads\" src=\"https://img.shields.io/npm/dm/@prettier/plugin-php.svg?style=flat-square\"\u003e\n  \u003c/a\u003e --\u003e\n  \u003ca href=\"#badge\"\u003e\n    \u003cimg alt=\"code style: prettier\" src=\"https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://gitter.im/jlongster/prettier\"\u003e\n    \u003cimg alt=\"Gitter\" src=\"https://img.shields.io/gitter/room/jlongster/prettier.svg?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://twitter.com/PrettierCode\"\u003e\n    \u003cimg alt=\"Follow+Prettier+on+Twitter\" src=\"https://img.shields.io/twitter/follow/prettiercode.svg?label=follow+prettier\u0026style=flat-square\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## Intro\n\nPrettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.\n\nThis plugin adds support for the PHP language to Prettier.\n\n\u003e [!NOTE]\n\u003e\n\u003e This plugin uses PSR / PER as guidance when making formatting decisions, but does not aim to be fully PSR / PER compliant. The idea is to stay reasonably close to how Prettier for JS works.\n\n### Can this be used in production?\n\nWe're considering the plugin to be stable when pure PHP files are formatted. Formatting of files that contain mixed PHP and HTML is still considered unstable - please see [open issues with the tag \"inline\"](https://github.com/prettier/plugin-php/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Ainline) for details.\n\nIf you want to use the plugin in production, we recommend limiting its scope to pure PHP files.\n\n### Input\n\n```php\n\u003c?php\narray_map(function($arg1,$arg2) use ( $var1, $var2 ) {\n    return $arg1+$arg2/($var+$var2);\n}, array(\"complex\"=\u003e\"code\",\"with\"=\u003e\n    function() {return \"inconsistent\";}\n,\"formatting\"=\u003e\"is\", \"hard\" =\u003e \"to\", \"maintain\"=\u003etrue));\n```\n\n### Output\n\n```php\n\u003c?php\n\narray_map(\n    function ($arg1, $arg2) use ($var1, $var2) {\n        return $arg1 + $arg2 / ($var + $var2);\n    },\n    [\n        \"complex\" =\u003e \"code\",\n        \"with\" =\u003e function () {\n            return \"inconsistent\";\n        },\n        \"formatting\" =\u003e \"is\",\n        \"hard\" =\u003e \"to\",\n        \"maintain\" =\u003e true,\n    ]\n);\n```\n\n## Playground\n\nYou can give the plugin a try in our [playground](https://loilo.github.io/prettier-php-playground/)!\n\n## Install\n\nyarn:\n\n```bash\nyarn add --dev prettier @prettier/plugin-php\n# or globally (pending https://github.com/prettier/prettier/issues/15141)\nyarn global add prettier @prettier/plugin-php\n```\n\nnpm:\n\n```bash\nnpm install --save-dev prettier @prettier/plugin-php\n# or globally (pending https://github.com/prettier/prettier/issues/15141)\nnpm install --global prettier @prettier/plugin-php\n```\n\n### Activate the plugin\n\nCreate or modify your [prettier configuration file](https://prettier.io/docs/en/configuration) to activate the plugin:\n\n```json\n{\n  \"plugins\": [\"@prettier/plugin-php\"]\n}\n```\n\n## Use\n\n### With Node.js\n\nIf you installed prettier as a local dependency, you can add prettier as a script in your `package.json`,\n\n```json\n{\n  \"scripts\": {\n    \"prettier\": \"prettier\"\n  }\n}\n```\n\nand then run it via\n\n```bash\nyarn run prettier path/to/file.php --write\n# or\nnpm run prettier -- path/to/file.php --write\n```\n\nIf you installed globally, run\n\n```bash\nprettier path/to/file.php --write\n```\n\n### In the Browser\n\nThis package exposes a `standalone.js` that can be used alongside Prettier's own `standalone.js` to make the PHP plugin work in browsers without a compile step.\n\nFirst, grab both standalone scripts from an npm CDN like [unpkg](https://unpkg.com/):\n\n```html\n\u003cscript src=\"https://unpkg.com/prettier/standalone.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"https://unpkg.com/@prettier/plugin-php/standalone.js\"\u003e\u003c/script\u003e\n```\n\nThen use Prettier with PHP, just like this:\n\n```js\nawait prettier.format(YOUR_CODE, {\n  plugins: prettierPlugins,\n  parser: \"php\",\n});\n```\n\nSee this code in action [in this basic demo](https://jsbin.com/butoruw/edit?html,output).\n\n### With Bundlers\n\nBundlers like webpack, Rollup or browserify automatically recognize how to handle the PHP plugin. Remember that even when using a bundler, you still have to use the standalone builds:\n\n```js\nimport prettier from \"prettier/standalone\";\nimport * as prettierPluginPhp from \"@prettier/plugin-php/standalone\";\n\nawait prettier.format(YOUR_CODE, {\n  plugins: [prettierPluginPhp],\n  parser: \"php\",\n});\n```\n\n## Configuration\n\nPrettier for PHP supports the following options. We recommend that all users set the `phpVersion` option.\n\n| Name               | Default    | Description                                                                                                                                                                                                                                                                            |\n| ------------------ | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `phpVersion`       | `\"7.0\"`    | Allows specifying the PHP version you're using. If you're using PHP 7.1 or later, setting this option will make use of modern language features in the printed output. If you're using PHP lower than 7.0, you'll have to set this option or Prettier will generate incompatible code. |\n| `printWidth`       | `80`       | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width))                                                                                                                                                                                        |\n| `tabWidth`         | `4`        | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)), The default is `4` based on the `PSR-2` coding standard.                                                                                                                                |\n| `useTabs`          | `false`    | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tabs))                                                                                                                                                                                               |\n| `singleQuote`      | `false`    | If set to `\"true\"`, strings that use double quotes but do not rely on the features they add, will be reformatted. Example: `\"foo\" -\u003e 'foo'`, `\"foo $bar\" -\u003e \"foo $bar\"`.                                                                                                               |\n| `trailingCommaPHP` | `true`     | If set to `true`, trailing commas will be added wherever possible. \u003cbr\u003e If set to `false`, no trailing commas are printed.                                                                                                                                                             |\n| `braceStyle`       | `\"per-cs\"` | If set to `\"per-cs\"`, prettier will move open brace for code blocks (classes, functions and methods) onto new line. \u003cbr\u003e If set to `\"1tbs\"`, prettier will move open brace for code blocks (classes, functions and methods) onto same line.                                            |\n| `requirePragma`    | `false`    | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma))                                                                                                                                                                                     |\n| `insertPragma`     | `false`    | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#insert-pragma))                                                                                                                                                                                      |\n\n## Ignoring code\n\nA comment `// prettier-ignore` will exclude the next node in the abstract syntax tree from formatting.\n\nFor example:\n\n```php\nmatrix(\n  1, 0, 0,\n  0, 1, 0,\n  0, 0, 1\n);\n\n// prettier-ignore\nmatrix(\n  1, 0, 0,\n  0, 1, 0,\n  0, 0, 1\n);\n```\n\nwill be transformed to\n\n```php\nmatrix(1, 0, 0, 0, 1, 0, 0, 0, 1);\n\n// prettier-ignore\nmatrix(\n  1, 0, 0,\n  0, 1, 0,\n  0, 0, 1\n)\n```\n\n## Editor integration\n\n### Visual Studio Code\n\nThe official [prettier plugin for vscode](https://github.com/prettier/prettier-vscode) supports plugins since Version 1.10.0. To enable it, install the extension and make sure the plugin is installed _locally_ (in your project folder).\n\nVisual Studio Code may not recognise the document selectors provided by this plugin, and so you can add php to your document selectors by adding the following line to `.vscode/settings.json`:\n\n```json\n  \"prettier.documentSelectors\": [\n    \"**/*.{js,jsx,ts,tsx,vue,html,css,scss,less,json,md,mdx,graphql,yaml,yml,php}\"\n  ]\n```\n\nYou may also need to declare php as the parser in your prettier config file:\n\n```json\n{\n  \"parser\": \"php\",\n  \"plugins\": [\"@prettier/plugin-php\"]\n}\n```\n\nSee (this issue)[https://github.com/prettier/plugin-php/issues/1730] for more discussion around potential VS Code solutions.\n\n### PhpStorm / IntelliJ / Jetbrains IDE\n\n- Install prettier and plugin locally `yarn add -D prettier @prettier/plugin-php`\n- Open Settings (File, Settings)\n- Go to Plugins Section, Select Marketplace, Search for Prettier, Install Plugin, Restart IDE\n- Open Settings, Search for Prettier, select Prettier in left settings navigation\n- Check prettier package has auto-detected, should be something like `myproject/node_modules/prettier`\n- Update Run for Files to include .php, eg: `{**/*,*}.{js,ts,jsx,tsx,php,json,scss,vue,md}`\n- Tick the On Save button, if you want your files formatting updated on file save\n- Clock OK to save settings\n\n_Note: Just pressing save does not reformat your current file unless the file has been modified in some way,\nalternatively you can use the Prettier shortcut Ctrl+Alt+Shift+P_\n\n### Sublime Text\n\nSublime Text support is available through Package Control and the [JsPrettier](https://packagecontrol.io/packages/JsPrettier) plugin.\n\n### Vim\n\nThe official [prettier plugin for vim](https://github.com/prettier/vim-prettier) has built-in support for plugin-php since 1.0.\n\n### Nova\n\nThe [Prettier⁺ Extension](https://extensions.panic.com/extensions/stonerl/stonerl.prettier/) has built-in support for plugin-php.\n\n#### ALE\n\nThe linting plugin ALE has built-in support for prettier and its plugins. Just add prettier to your [list of fixers](https://github.com/w0rp/ale#2ii-fixing). For example:\n\n```vim\nlet g:ale_fixers={\n  \\'javascript': ['prettier'],\n  \\'json': ['prettier'],\n  \\'php': ['prettier'],\n\\}\n```\n\n#### Custom\n\nAlternatively, adding the following to `.vimrc` will define a custom command `:PrettierPhp` that runs the plugin while preserving the cursor position and run it on save.\n\n```vim\n\" Prettier for PHP\nfunction PrettierPhpCursor()\n  let save_pos = getpos(\".\")\n  %! prettier --stdin --parser=php\n  call setpos('.', save_pos)\nendfunction\n\" define custom command\ncommand PrettierPhp call PrettierPhpCursor()\n\" format on save\nautocmd BufwritePre *.php PrettierPhp\n```\n\n## Integration for other tools\n\n### PHP-CS-Fixer\n\nSee `docs/recipes/php-cs-fixer` for integration help, code can also be found in https://gist.github.com/Billz95/9d5fad3af728b88540fa831b73261733\n\n## Contributing\n\nIf you're interested in contributing to the development of Prettier for PHP, you can follow the [CONTRIBUTING guide from Prettier](https://github.com/prettier/prettier/blob/master/CONTRIBUTING.md), as it all applies to this repository too.\n\nTo test it out on a PHP file:\n\n- Clone this repository.\n- Run `yarn`.\n- Create a file called `test.php`.\n- Run `yarn prettier test.php` to check the output.\n\n## Maintainers\n\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003ca href=\"https://github.com/czosel\"\u003e\n          \u003cimg width=\"150\" height=\"150\" src=\"https://github.com/czosel.png?v=3\u0026s=150\"\u003e\n          \u003c/br\u003e\n          Christian Zosel\n        \u003c/a\u003e\n      \u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003ca href=\"https://github.com/evilebottnawi\"\u003e\n          \u003cimg width=\"150\" height=\"150\" src=\"https://github.com/evilebottnawi.png?v=3\u0026s=150\"\u003e\n          \u003c/br\u003e\n          Evilebot Tnawi\n        \u003c/a\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003ctbody\u003e\n\u003c/table\u003e\n","funding_links":["https://github.com/sponsors/prettier","https://opencollective.com/prettier","https://thanks.dev/u/gh/prettier","https://tidelift.com/funding/github/npm/prettier"],"categories":["PHP","Development"],"sub_categories":["Formatting"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprettier%2Fplugin-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprettier%2Fplugin-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprettier%2Fplugin-php/lists"}