{"id":15027722,"url":"https://github.com/mansoorkhan96/php-cs-fixer","last_synced_at":"2025-04-09T20:22:51.682Z","repository":{"id":44538517,"uuid":"363682405","full_name":"mansoorkhan96/php-cs-fixer","owner":"mansoorkhan96","description":"PHP CS Fixer extension for VS Code with zero config","archived":false,"fork":false,"pushed_at":"2024-08-21T12:54:28.000Z","size":6493,"stargazers_count":12,"open_issues_count":3,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T22:14:34.706Z","etag":null,"topics":["php","php-cs-fixer","php8","php81","prettier","prettier-php","visual-studio","visual-studio-code","vscode","vscode-extension"],"latest_commit_sha":null,"homepage":"https://marketplace.visualstudio.com/items?itemName=mansoorkhan96.php-cs-fixer","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/mansoorkhan96.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"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}},"created_at":"2021-05-02T15:22:07.000Z","updated_at":"2024-11-29T05:43:07.000Z","dependencies_parsed_at":"2025-02-15T20:33:35.614Z","dependency_job_id":"e9e4b2d0-3f9d-4a89-9cd5-5638d97a7951","html_url":"https://github.com/mansoorkhan96/php-cs-fixer","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mansoorkhan96%2Fphp-cs-fixer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mansoorkhan96%2Fphp-cs-fixer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mansoorkhan96%2Fphp-cs-fixer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mansoorkhan96%2Fphp-cs-fixer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mansoorkhan96","download_url":"https://codeload.github.com/mansoorkhan96/php-cs-fixer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248104915,"owners_count":21048421,"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":["php","php-cs-fixer","php8","php81","prettier","prettier-php","visual-studio","visual-studio-code","vscode","vscode-extension"],"created_at":"2024-09-24T20:06:56.863Z","updated_at":"2025-04-09T20:22:51.648Z","avatar_url":"https://github.com/mansoorkhan96.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\r\n    \u003cimg width=\"150px\" height=\"150px\" src=\"icon.png\"/\u003e\r\n\u003c/div\u003e\r\n\r\n\u003cdiv align=\"center\"\u003e\u003ch1\u003eVsCode PHP CS Fixer\u003c/h1\u003e\u003c/div\u003e\r\n\r\nThis extension requires almost zero configuration to format `.php` files. It uses `v3.62.0` of [cs.symfony.com](https://cs.symfony.com/) by default but that's easily replaceable. As long as PHP 7+ is installed on your system and in your PATH, the extension should work out of the box.\r\n\r\n![demo](simple-demo.gif)\r\n\r\n# Installation\r\n\r\nSimply install the extension from marketplace and add it as the default formatter for PHP. In your settings.json file add/update following.\r\n\r\n```json\r\n\"[php]\": {\r\n    \"editor.defaultFormatter\": \"mansoorkhan96.php-cs-fixer\"\r\n}\r\n```\r\n\r\n## Extension Optional Settings\r\n\r\nThis extension contributes the following settings:\r\n\r\n-   `php-cs-fixer.toolPath`: The path to the php-cs-fixer tool (default: \"\")\r\n-   `php-cs-fixer.useCache`: Use a cache file when fixing files (--using-cache) (default: true)\r\n-   `php-cs-fixer.allowRisky`: Determines whether risky rules are allowed (--allow-risky) (default: false)\r\n-   `php-cs-fixer.config`: Path to a config file (--config) (default: \"WorkspaceFolder/.php-cs-fixer.php\" OR \"WorkspaceFolder/.php-cs-fixer.dist.php\")\r\n-   `php-cs-fixer.fixOnSave`: Runs fix command on save (default: true)\r\n-   `php-cs-fixer.rules`: Rules to use when fixing files (--rules) (default: \"@PSR12,@PSR1,@PSR2,@Symfony,-yoda_style\")\r\n-   `php-cs-fixer.preset`: Use a preset from: laravel, PER, PSR12, symfony. You should remove it if you want to use a config file.\r\n-   `php-cs-fixer.phpCmd`: Specify path to PHP command (default: \"php\").\r\n\r\n### Adding PHP CS Fixer from a composer dependency\r\n\r\nYou can require [PHP CS Fixer](https://packagist.org/packages/friendsofphp/php-cs-fixer) as composer dependency in your project and the extension will load it automatically for you.\r\n\r\nIf extension could not find/load the binary from `/vendor/bin/php-cs-fixer`, it would default to the binary included in extension.\r\n\r\n### Manually adding PHP CS Fixer binary file?\r\n\r\n[Download](https://cs.symfony.com/) the binary file and provide the file path to the extension.\r\n\r\nOpen `settings.json` file (Ctrl + Shift + P) and add the following setting:\r\n\r\n```json\r\n\"php-cs-fixer.toolPath\": \"path\\\\php-cs-fixer.phar\",\r\n```\r\n\r\nOn Windows:\r\n\r\n```json\r\n\"php-cs-fixer.toolPath\": \"C:\\\\Users\\\\username\\\\.vscode\\\\php-cs-fixer.phar\",\r\n```\r\n\r\n### Config File\r\n\r\nThis extension formats `.php` files based on specified rules. Commonly these rules are defined in a `.php-cs-fixer.dist.php` OR `.php-cs-fixer.php` config file inside your project root path. The extension would try to pick a config file with above filenames, if not found it uses default rules.\r\n\r\nYou can also define a `global` config file which can be used accross all projects.\r\n\r\nOpen `settings.json` file (Ctrl + Shift + P) and add the following setting:\r\n\r\n```json\r\n\"php-cs-fixer.config\": \"/full/config/file/path\"\r\n```\r\n\r\nOn Windows:\r\n\r\n```json\r\n\"php-cs-fixer.config\": \"C:\\\\Users\\\\username\\\\.vscode\\\\.php-cs-fixer.php\"\r\n```\r\n\r\n### Path to PHP Command\r\n\r\nYou can specify path to PHP Command using the config.\r\n\r\n```json\r\n\"php-cs-fixer.phpCmd\": \"/Users/mansoor/Library/Application Support/Herd/bin/php\",\r\n```\r\n\r\n#### Not sure which rules to add?\r\n\r\nTry out following config rules. Try to remove a rule and observe the changes.\r\n\r\n```php\r\n\u003c?php\r\n\r\n$config = new PhpCsFixer\\Config();\r\n\r\nreturn $config\r\n    -\u003esetRules([\r\n        '@PSR12' =\u003e true,\r\n        'new_with_braces' =\u003e false,\r\n        'array_indentation' =\u003e true,\r\n        'array_syntax' =\u003e ['syntax' =\u003e 'short'],\r\n        'combine_consecutive_unsets' =\u003e true,\r\n        'multiline_whitespace_before_semicolons' =\u003e true,\r\n        'single_quote' =\u003e true,\r\n        'blank_line_before_statement' =\u003e true,\r\n        'braces' =\u003e [\r\n            'allow_single_line_closure' =\u003e true,\r\n        ],\r\n        'concat_space' =\u003e ['spacing' =\u003e 'one'],\r\n        'declare_equal_normalize' =\u003e true,\r\n        'function_typehint_space' =\u003e true,\r\n        'include' =\u003e true,\r\n        'lowercase_cast' =\u003e true,\r\n        'no_multiline_whitespace_around_double_arrow' =\u003e true,\r\n        'no_spaces_around_offset' =\u003e true,\r\n        'no_unused_imports' =\u003e true,\r\n        'no_whitespace_before_comma_in_array' =\u003e true,\r\n        'no_whitespace_in_blank_line' =\u003e true,\r\n        'object_operator_without_whitespace' =\u003e true,\r\n        'single_blank_line_before_namespace' =\u003e true,\r\n        'ternary_operator_spaces' =\u003e true,\r\n        'trailing_comma_in_multiline' =\u003e true,\r\n        'trim_array_spaces' =\u003e true,\r\n        'unary_operator_spaces' =\u003e true,\r\n        'binary_operator_spaces' =\u003e true,\r\n        'whitespace_after_comma_in_array' =\u003e true,\r\n        'single_trait_insert_per_statement' =\u003e false,\r\n    ])\r\n    -\u003esetLineEnding(\"\\n\");\r\n```\r\n\r\nYou can find the complete rule set [here](https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/doc/ruleSets/index.rst)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmansoorkhan96%2Fphp-cs-fixer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmansoorkhan96%2Fphp-cs-fixer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmansoorkhan96%2Fphp-cs-fixer/lists"}