{"id":22868653,"url":"https://github.com/nexusphp/cs-config","last_synced_at":"2025-05-05T19:54:00.932Z","repository":{"id":44471792,"uuid":"316460803","full_name":"NexusPHP/cs-config","owner":"NexusPHP","description":":factory: A factory for custom rulesets for PHP CS Fixer.","archived":false,"fork":false,"pushed_at":"2025-02-23T15:16:36.000Z","size":548,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"3.x","last_synced_at":"2025-04-19T19:13:36.907Z","etag":null,"topics":["configuration-factory","custom-ruleset","php","rulesets"],"latest_commit_sha":null,"homepage":"","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/NexusPHP.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":"2020-11-27T09:46:37.000Z","updated_at":"2025-02-23T15:16:39.000Z","dependencies_parsed_at":"2023-12-29T13:34:21.281Z","dependency_job_id":"2b3bf6bf-102a-4117-a78e-24ecc6180b85","html_url":"https://github.com/NexusPHP/cs-config","commit_stats":{"total_commits":201,"total_committers":2,"mean_commits":100.5,"dds":0.00995024875621886,"last_synced_commit":"9ed62cbc3cb48136e7ef2c18f3d6579a05638e13"},"previous_names":[],"tags_count":58,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NexusPHP%2Fcs-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NexusPHP%2Fcs-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NexusPHP%2Fcs-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NexusPHP%2Fcs-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NexusPHP","download_url":"https://codeload.github.com/NexusPHP/cs-config/tar.gz/refs/heads/3.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252567461,"owners_count":21769242,"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":["configuration-factory","custom-ruleset","php","rulesets"],"created_at":"2024-12-13T12:36:47.122Z","updated_at":"2025-05-05T19:54:00.926Z","avatar_url":"https://github.com/NexusPHP.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nexus CS Config\n\n[![PHP version](https://img.shields.io/packagist/php-v/nexusphp/cs-config)](https://php.net)\n[![build](https://github.com/NexusPHP/cs-config/actions/workflows/build.yml/badge.svg)](https://github.com/NexusPHP/cs-config/actions/workflows/build.yml)\n[![Coverage Status](https://coveralls.io/repos/github/NexusPHP/cs-config/badge.svg?branch=develop)](https://coveralls.io/github/NexusPHP/cs-config?branch=develop)\n[![Latest Stable Version](https://poser.pugx.org/nexusphp/cs-config/v)](//packagist.org/packages/nexusphp/cs-config)\n[![license MIT](https://img.shields.io/github/license/nexusphp/cs-config)](LICENSE)\n[![Total Downloads](https://poser.pugx.org/nexusphp/cs-config/downloads)](//packagist.org/packages/nexusphp/cs-config)\n\nThis library provides a factory for custom rulesets for [`friendsofphp/php-cs-fixer`][1].\n\n[1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer\n\n## Installation\n\nYou can add this library as a local, per-project dependency to your project\nusing [Composer](https://getcomposer.org/):\n\n    composer require nexusphp/cs-config\n\nIf you only need this library during development, for instance to run your project's test suite,\nthen you should add it as a development-time dependency:\n\n    composer require --dev nexusphp/cs-config\n\n## Configuration\n\n* Create a `.php-cs-fixer.dist.php` at the root of your project:\n\n```php\n\u003c?php\n\nuse Nexus\\CsConfig\\Factory;\nuse Nexus\\CsConfig\\Ruleset\\Nexus82;\n\nreturn Factory::create(new Nexus82())-\u003eforProjects();\n\n```\n\n* Include the cache file in your `.gitignore`. By\ndefault, the cache file will be saved in the project root.\n\n```diff\n vendor/\n\n+# php-cs-fixer\n+.php-cs-fixer.php\n+.php-cs-fixer.cache\n```\n\n## Advanced Configuration\n\n### Adding Preformatted License Header\n\nYou can create a preformatted license header to all PHP files by using the public `forLibrary()` method\ninstead of `forProjects()`. This method accepts two required arguments (the library name and author) and\ntwo optional arguments (the email address and starting year of license).\n\n* Scenario 1: Providing all arguments\n```diff\n \u003c?php\n\n use Nexus\\CsConfig\\Factory;\n use Nexus\\CsConfig\\Ruleset\\Nexus82;\n\n-return Factory::create(new Nexus82())-\u003eforProjects();\n+return Factory::create(new Nexus82())-\u003eforLibrary('My Library', 'John Doe', 'john@doe.com', 2020);\n```\n\nThis setting will configure a license header similar to below:\n\n```php\n\u003c?php\n\n/**\n * This file is part of My Library.\n *\n * (c) 2020 John Doe \u003cjohn@doe.com\u003e\n *\n * For the full copyright and license information, please view\n * the LICENSE file that was distributed with this source code.\n */\n\nnamespace Nexus\\CsConfig;\n```\n\n* Scenario 2: Providing only the required arguments\n\nIf you opted not to provide any of the optional arguments (i.e., email address, starting license year),\nthese will not be shown on the license header allowing flexibility on the copyright portion.\n\n```diff\n\u003c?php\n\n use Nexus\\CsConfig\\Factory;\n use Nexus\\CsConfig\\Ruleset\\Nexus82;\n\n-return Factory::create(new Nexus82())-\u003eforProjects();\n+return Factory::create(new Nexus82())-\u003eforLibrary('My Library', 'John Doe');\n```\n\nThis will give the following license header:\n\n```php\n\u003c?php\n\n/**\n * This file is part of My Library.\n *\n * (c) John Doe\n *\n * For the full copyright and license information, please view\n * the LICENSE file that was distributed with this source code.\n */\n\nnamespace Nexus\\CsConfig;\n```\n\n### Overriding Rules in a Ruleset\n\nIf you feel that a specific rule in the ruleset is not appropriate for you, you can override it instead of creating a new ruleset:\n\n```diff\n \u003c?php\n\n use Nexus\\CsConfig\\Factory;\n use Nexus\\CsConfig\\Ruleset\\Nexus82;\n\n-return Factory::create(new Nexus82())-\u003eforProjects();\n+return Factory::create(new Nexus82(), [\n+    'binary_operator_spaces' =\u003e false,\n+])-\u003eforProjects();\n\n```\n\n### Specifying Options to `PhpCsFixer\\Config`\n\nThe `Factory` class returns an instance of `PhpCsFixer\\Config` and fully supports all of\nits properties setup. You can pass an array to the third parameter of `Factory::create()`\ncontaining your desired options.\n\n**Options**\n\n| Key            | Allowed Types                            | Default                              |\n| -------------- | :--------------------------------------: | :----------------------------------: |\n| cacheFile      | `string`                                 | `.php-cs-fixer.cache`                |\n| customFixers   | `FixerInterface[], iterable, \\Traversable` | `[]`                                 |\n| finder         | `iterable, string[], \\Traversable`         | default `PhpCsFixer\\Finder` instance |\n| format         | `string`                                 | `txt`                                |\n| hideProgress   | `bool`                                   | `false`                              |\n| indent         | `string`                                 | `'    '` // 4 spaces                 |\n| lineEnding     | `string`                                 | `\"\\n\"`                               |\n| isRiskyAllowed | `bool`                                   | `false`                              |\n| usingCache     | `bool`                                   | `true`                               |\n| customRules    | `array`                                  | `[]`                                 |\n\n```diff\n \u003c?php\n\n use Nexus\\CsConfig\\Factory;\n use Nexus\\CsConfig\\Ruleset\\Nexus82;\n\n-return Factory::create(new Nexus82())-\u003eforProjects();\n+return Factory::create(new Nexus82(), [], [\n+    'usingCache'  =\u003e false,\n+    'hideProgress =\u003e true,\n+])-\u003eforProjects();\n```\n\n## Customization of Ruleset\n\nWhat is the purpose of a configuration factory if not able to create a custom ruleset for\nan organization-wide usage, right? Well, you are not constrained to use the default rulesets\nand putting a long array of overrides. That's pretty nasty.\n\nThe way to achieve this is dependent on you but the main idea is creating a new ruleset that\nextends `Nexus\\CsConfig\\Ruleset\\AbstractRuleset`. Yup, it's that easy. Then you just need to\nprovide details for its required four (4) protected properties.\n\n```php\n\u003c?php\n\nnamespace MyCompany\\CodingStandards\\Ruleset;\n\nuse Nexus\\CsConfig\\Ruleset\\AbstractRuleset;\n\nfinal class MyCompany extends AbstractRuleset\n{\n  public function __construct()\n  {\n    $this-\u003ename = 'My Company';\n    $this-\u003erules = [\n      '@PSR2' =\u003e true,\n      ...\n    ];\n    $this-\u003erequiredPHPVersion = 80200;\n    $this-\u003eautoActivateIsRiskyAllowed = true;\n  }\n}\n\n```\n\nThen, in creating your `.php-cs-fixer.dist.php`, use your own ruleset.\n\n```php\n\u003c?php\n\nuse Nexus\\CsConfig\\Factory;\nuse MyCompany\\CodingStandards\\Ruleset\\MyCompany;\n\nreturn Factory::create(new MyCompany())-\u003eforProjects();\n\n```\n\n## Credits\n\nThis project is inspired by and an enhancement of [`ergebnis/php-cs-fixer-config`](https://github.com/ergebnis/php-cs-fixer-config).\n\n## Contributing\n\nContributions are very much welcome. If you see an improvement or bugfix, open a [PR](https://github.com/NexusPHP/cs-config/pulls) now!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnexusphp%2Fcs-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnexusphp%2Fcs-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnexusphp%2Fcs-config/lists"}