{"id":28202217,"url":"https://github.com/justcoded/php-cs-fixer","last_synced_at":"2026-02-21T21:04:18.018Z","repository":{"id":283316620,"uuid":"951191904","full_name":"justcoded/php-cs-fixer","owner":"justcoded","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-04T09:34:31.000Z","size":44,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-06T02:30:49.963Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/justcoded.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":"2025-03-19T09:53:51.000Z","updated_at":"2025-07-04T09:34:24.000Z","dependencies_parsed_at":"2025-03-19T16:44:44.706Z","dependency_job_id":null,"html_url":"https://github.com/justcoded/php-cs-fixer","commit_stats":null,"previous_names":["justcoded/php-cs-fixer"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/justcoded/php-cs-fixer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justcoded%2Fphp-cs-fixer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justcoded%2Fphp-cs-fixer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justcoded%2Fphp-cs-fixer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justcoded%2Fphp-cs-fixer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/justcoded","download_url":"https://codeload.github.com/justcoded/php-cs-fixer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justcoded%2Fphp-cs-fixer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29694100,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T18:18:25.093Z","status":"ssl_error","status_checked_at":"2026-02-21T18:18:22.435Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2025-05-16T23:14:26.347Z","updated_at":"2026-02-21T21:04:18.013Z","avatar_url":"https://github.com/justcoded.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JustCoded PHP-CS-Fixer\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://packagist.org/packages/justcoded/php-cs-fixer\"\u003e\n        \u003cimg src=\"https://img.shields.io/packagist/v/justcoded/php-cs-fixer.svg?style=flat-rounded\" alt=\"Latest Stable Version\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/justcoded/php-cs-fixer\"\u003e\n        \u003cimg src=\"https://img.shields.io/packagist/dt/justcoded/php-cs-fixer.svg?style=flat-rounded\" alt=\"Total Downloads\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/MasterRO94/laravel-mail-viewer/blob/master/LICENSE\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/license/MasterRO94/laravel-mail-viewer\" alt=\"License\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg\" alt=\"StandWithUkraine\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\nA preconfigured **[Easy Coding Standard](https://github.com/easy-coding-standard/easy-coding-standard) (ECS)** wrapper with a set of recommended rules.  \nProvides an easy way to check and fix PHP code style both via CLI and programmatically.\n\n- ✅ Framework-agnostic\n- ✅ Built-in Laravel integration\n- ✅ Pre-configured with popular coding standards\n- ✅ Programmatic interface to check \u0026 fix code\n\n---\n\n## 📦 Installation\n\n```bash\ncomposer require justcoded/php-cs-fixer\n```\nfor only CLI usage you could install as `dev` dependency\n```bash\ncomposer require justcoded/php-cs-fixer --dev\n```\n\n---\n\n## 🚀 Usage\n\n### CLI Usage\n\nAfter installation, the package exposes the ECS binary:\n\n```bash\n# Check code style:\n./vendor/bin/ecs check\n\n# Automatically fix code style issues:\n./vendor/bin/ecs check --fix\n```\n\nYou can also specify paths:\n\n```bash\n./vendor/bin/ecs check path/to/your/files\n```\n\n---\n\n### Programmatic Usage\n\nThe package provides the `JustCoded\\PhpCsFixer\\Services\\CodeFixer` class to run checks and fixes within your PHP code.\n\n#### Constructor\n\n```php\nnew CodeFixer(array $config = [])\n```\n\n**Available Config Options:**\n\n| Option | Type         | Default | Description                                                                                                               |\n|-------|--------------|---------|---------------------------------------------------------------------------------------------------------------------------|\n| `tty` | bool \\| null | false   | Whether to enable TTY mode in the process. Useful for colored output. Uses `Process::isTtySupported()` if value set to null |\n\n---\n\n### Basic Example:\n\n```php\nuse JustCoded\\PhpCsFixer\\Services\\CodeFixer;\n\n$fixer = new CodeFixer();\n\n// Check mode\n$result = $fixer-\u003echeck();\n\nif (! $result-\u003esuccessful) {\n    echo \"Code issues found:\\n\";\n    echo $result-\u003eoutput;\n}\n\n// Fix mode\n$result = $fixer-\u003efix();\necho $result-\u003eoutput;\n```\n\n---\n\n### Custom Paths \u0026 Config:\n\n```php\nuse JustCoded\\PhpCsFixer\\Services\\CodeFixer;\n\n$fixer = new CodeFixer(config: ['tty' =\u003e true]);\n\n// Check a specific path\n$result = $fixer-\u003echeck(path: ['app/', 'tests/']);\n\n// Fix specific path with TTY disabled\n$result = $fixer-\u003efix(path: 'src/', config: ['tty' =\u003e false]);\n```\n\n---\n\n### Advanced Usage - Direct `execute()`:\n\nYou can also use the more flexible `execute()` method:\n\n```php\nuse JustCoded\\PhpCsFixer\\Services\\CodeFixer;\n\n$fixer = new CodeFixer();\n\n$result = $fixer-\u003eexecute(\n    path: 'src/',\n    fix: true,\n    config: ['tty' =\u003e false],\n    callback: function ($type, $buffer) {\n        echo $buffer; // Stream process output\n    },\n);\n\necho $result-\u003eoutput;\n```\n\n---\n\n### Result Object:\n\nAll methods return a `CodeFixerResult`:\n\n```php\nclass CodeFixerResult\n{\n    public bool $successful;\n    public string $output;\n}\n```\n\n## ⚙️ Laravel Integration\n\nWhen used in a Laravel project, this package provides **seamless integration** out of the box.\n\n### Features:\n\n- **Service Provider Auto-Discovery**  \n  No manual registration is needed. The package auto-registers:\n\n  ```php\n  JustCoded\\PhpCsFixer\\Providers\\PhpCsFixerServiceProvider\n  ```\n\n- **Configuration File**  \n  After installation, the package publishes a configuration file:\n\n  ```bash\n  php artisan vendor:publish --tag=php-cs-fixer-config\n  ```\n\n  This creates `config/php-cs-fixer.php` containing:\n\n  ```php\n  return [\n      /*\n      | If null Symfony\\Component\\Process\\Process::isTtySupported() is used.\n      | You probably want it to be false to be able to capture the output.\n      */\n      'tty' =\u003e env('PHP_CS_FIXER_TTY', false),\n  ];\n  ```\n\n  You can adjust the default `tty` behavior by changing this config or setting the `PHP_CS_FIXER_TTY` environment variable.\n\n- **Service Container Binding**  \n  The package registers the `CodeFixer` class as a **scoped singleton** within Laravel’s service container.\n\n  You can easily inject it wherever needed:\n\n  ```php\n  use JustCoded\\PhpCsFixer\\Services\\CodeFixer;\n\n  public function __construct(\n      protected CodeFixer $fixer,\n  ) {}\n\n  public function run()\n  {\n      $result = $this-\u003efixer-\u003echeck();\n  \n      echo $result-\u003eoutput;\n  }\n  ```\n\n  Or resolve it manually:\n\n  ```php\n  $fixer = app(JustCoded\\PhpCsFixer\\Services\\CodeFixer::class);\n  ```\n\n---\n\n## 📚 Configured Standards\n\nThe package includes:\n\n- **FriendsofPHP/php-cs-fixer**\n- **Symplify Easy Coding Standard**\n- **Slevomat Coding Standard**\n- **PHP_CodeSniffer**\n- **Custom fixers from kubawerlos/php-cs-fixer-custom-fixers**\n\nIt ships pre-configured with best-practice rules.  \nHowever, you can override the configuration by placing your own `ecs.php` in the project root.\n\n---\n\n## 🛠️ Custom `ecs.php` Configuration\n\nBy default, **PhpCsFixer** comes with a preconfigured `ecs.php` configuration file located inside the package. However, you can easily override this configuration by placing your own `ecs.php` file at the root of your project or specify `ecs_path` config param.\n\n**How it works:**\n\n- If a `ecs.php` file exists in specified `ecs_path` it will be automatically used.\n- If a `ecs.php` file exists in your project's root directory, it will be automatically used when running `check` or `fix` commands (both CLI and programmatic usage).\n- If no custom config is found, the package's default configuration will be applied.\n\n### Example: Providing Custom `ecs.php`\n\n1. Create a file in your project root:\n\n```php\n// ecs.php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Symplify\\EasyCodingStandard\\Config\\ECSConfig;\nuse Symplify\\EasyCodingStandard\\ValueObject\\Option;\n\nreturn static function (ECSConfig $ecsConfig): void {\n    $ecsConfig-\u003epaths([\n        __DIR__ . '/app',\n        __DIR__ . '/src',\n        __DIR__ . '/tests',\n    ]);\n\n    $ecsConfig-\u003esets([\n        \\Symplify\\EasyCodingStandard\\ValueObject\\Set\\SetList::PSR_12,\n    ]);\n};\n```\n\n2. Run:\n\n```bash\n./vendor/bin/ecs check\n```\n\nYour custom rules and paths will now be applied.\n\n---\n\n**Note:**  \nWhen using **Laravel integration**, the same behavior applies. You can manage your own `ecs.php` file without needing to modify the package. The `CodeFixer` service will detect and use your config automatically.\n\n---\n\n## 🧪 Testing\n\n```bash\ncomposer test\n```\n\n---\n\n## 📝 License\n\nThis package is open-sourced software licensed under the [MIT license](LICENSE).\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustcoded%2Fphp-cs-fixer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjustcoded%2Fphp-cs-fixer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustcoded%2Fphp-cs-fixer/lists"}