{"id":15003504,"url":"https://github.com/26b/php-pre-commit","last_synced_at":"2025-10-30T11:30:27.431Z","repository":{"id":45077120,"uuid":"351842308","full_name":"26B/php-pre-commit","owner":"26B","description":"Pre-commit git hook to help keep code within PHP standards.","archived":false,"fork":false,"pushed_at":"2024-05-24T11:31:49.000Z","size":79,"stargazers_count":7,"open_issues_count":7,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-14T19:06:32.881Z","etag":null,"topics":["git","linting","php","phpcs","standards"],"latest_commit_sha":null,"homepage":"","language":"Shell","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/26B.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-03-26T16:18:10.000Z","updated_at":"2024-05-21T19:50:43.000Z","dependencies_parsed_at":"2024-10-12T07:41:08.110Z","dependency_job_id":"603f5c12-f67d-4f33-9b6c-f7c2f2f2a0cb","html_url":"https://github.com/26B/php-pre-commit","commit_stats":{"total_commits":37,"total_committers":5,"mean_commits":7.4,"dds":0.6486486486486487,"last_synced_commit":"a253fb1898c9a4152cc112c83b924e1d93888094"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/26B%2Fphp-pre-commit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/26B%2Fphp-pre-commit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/26B%2Fphp-pre-commit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/26B%2Fphp-pre-commit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/26B","download_url":"https://codeload.github.com/26B/php-pre-commit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238955683,"owners_count":19558452,"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":["git","linting","php","phpcs","standards"],"created_at":"2024-09-24T18:58:43.590Z","updated_at":"2025-10-30T11:30:27.114Z","avatar_url":"https://github.com/26B.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php-pre-commit\n\nPre-commit git hook for enforcing php standards.\n\nCurrently uses PHP_CodeSniffer (PHPCS) and corrects .php staged files according to a phpcs config file (usually a phpcs.xml).\n\nInstall via the composer command:\n\n```bash\ncomposer require --dev 26b/php-pre-commit\n```\n\nIn order for the hooks to be moved into the `.git/hooks` folder add the following to the project's `composer.json`:\n\n```json\n\"scripts\": {\n    \"post-install-cmd\": \"php-pre-commit\",\n    \"post-update-cmd\": \"php-pre-commit\"\n}\n```\n\nWith `composer install` or `composer update` the `pre-commit` hook will be moved into `.git/hooks`.\n\nIf you want to skip the pre-commit execution, you can add the argument `--no-verify` to `git commit`.\n\n\u003e [!IMPORTANT]\n\u003e This package **does not require** PHPCS because it is up to you whether you want to use a local or global `phpcs`. Local `phpcs` takes precedence when the pre-commit runs. You can require them in the following way:\n\u003e\n\u003e ```bash\n\u003e # Local\n\u003e composer require --dev squizlabs/php_codesniffer\n\u003e # Or global\n\u003e composer global require squizlabs/php_codesniffer\n\u003e ```\n\n## Use Cases\n\n### Local PHPCS\n\nIf you intend to use different sets of standards in different repositories we advise you to install `php_codesniffer` locally, this will make sure that there will be no conflicts when configuring `phpcs --config-set ...` later on. In case you choose the local approach make sure to correct the PHPCS path on the examples below.\n\nUsually it would be something like changing all `phpcs` references to `./vendor/bin/phpcs` (or any other local path).\n\n### WordPress\n\n#### Setup WordPress Standards (Manual)\n\nFirst we need to clone the WordPress standards repository. It should be placed in a directory that `phpcs` can access. We placed ours in the home directory `wpcs` directory in root. Clone the repository into the `wpcs` folder via:\n\n```bash\ngit clone git@github.com:WordPress/WordPress-Coding-Standards.git --depth=1 --branch 3.1.0 ~/wpcs\n```\n\nSecondly, we need to tell `phpcs` where these standards are.\n\n```bash\nphpcs --config-set installed_paths /full/path/to/wpcs\n```\n\nFinally, in order to check that `phpcs` recognises and uses the standards, we can check it like this:\n\n```bash\n$ phpcs -i\nThe installed coding standards are PEAR, Zend, PSR2, Squiz, PSR1, PSR12, WordPress, WordPress-Extra, WordPress-Docs and WordPress-Core\n```\n\nThe output should resemble this, with the WordPress standards. If they are missing, `phpcs` might not be recognising the path. Check its paths via:\n\n```bash\n$ phpcs --config-show\nUsing config file: /full/path/to/global/composer/vendor/squizlabs/php_codesniffer/CodeSniffer.conf\n\ndefault_standard: WordPress-Extra\ninstalled_paths:  /full/path/to/wpcs\n```\n\n#### Alternative (Automatic)\n\nAs an alternative you can use [PHP_CodeSniffer Standards Composer Installer Plugin](https://github.com/Dealerdirect/phpcodesniffer-composer-installer) which helps to automatically link the wanted standards to phpcs. Be aware that it requires `phpcs` locally and so our `pre-commit` hook will use that phpcs. We can then require this package and WPCS in the following manner:\n\n```bash\ncomposer require --dev dealerdirect/phpcodesniffer-composer-installer wp-coding-standards/wpcs\n```\n\nOr add them to the composer.json:\n\n```json\n\"require-dev\": {\n    \"dealerdirect/phpcodesniffer-composer-installer\": \"*\",\n    \"wp-coding-standards/wpcs\": \"*\"\n}\n```\n\nAnd add scripts, to configure `phpcs` correctly upon `composer install`, like this:\n\n```json\n\"scripts\": {\n    \"install-codestandards\": [\n        \"Dealerdirect\\\\Composer\\\\Plugin\\\\Installers\\\\PHPCodeSniffer\\\\Plugin::run\"\n    ],\n    \"post-install-cmd\": [\n        \"php-pre-commit\",\n        \"@install-codestandards\"\n    ]\n}\n```\n\n### Laravel\n\n#### Automatic Setup\n\nHere, you can also use [PHP_CodeSniffer Standards Composer Installer Plugin](https://github.com/Dealerdirect/phpcodesniffer-composer-installer) to automatically link the Laravel standards to phpcs. Again, make sure `phpcs` is installed locally and so our `pre-commit`. We just need to require [emielmolenaar/phpcs-laravel](https://github.com/emielmolenaar/phpcs-laravel) package and we are done:\n\n```bash\ncomposer require --dev emielmolenaar/phpcs-laravel\n```\n\nFinally, add the same scripts to configure `phpcs` correctly upon `composer install`:\n\n```json\n\"scripts\": {\n    \"install-codestandards\": [\n        \"Dealerdirect\\\\Composer\\\\Plugin\\\\Installers\\\\PHPCodeSniffer\\\\Plugin::run\"\n    ],\n    \"post-install-cmd\": [\n        \"php-pre-commit\",\n        \"@install-codestandards\"\n    ]\n}\n```\n\n#### Manual Setup\n\nA Laravel's coding standard repository that is being updated consistently is [emielmolenaar/phpcs-laravel](https://github.com/emielmolenaar/phpcs-laravel). We will now proceed to the configuration (very similar to the *WordPress configuration*). First clone [emielmolenaar/phpcs-laravel](https://github.com/emielmolenaar/phpcs-laravel) repository:\n\n```bash\ngit clone https://github.com/emielmolenaar/phpcs-laravel.git --branch 2.0\n```\n\nAgain, tell to `phpcs` where the standards are.\n\n```bash\nphpcs --config-set installed_paths /full/path/to/phpcs-laravel\n```\n\nOnce more, make sure `phpcs` recognises and uses the installed standards:\n\n```bash\n$ phpcs -i\nThe installed coding standards are PEAR, Zend, PSR2, MySource, Squiz, PSR1, PSR12 and phpcs-laravel\n```\n\nThe `--config-show` will give the following output:\n\n```bash\n$ phpcs --config-show\nUsing config file: /full/path/to/composer/vendor/squizlabs/php_codesniffer/CodeSniffer.conf\n\ninstalled_paths: /full/path/to/phpcs-laravel\n```\n\n## Troubleshooting\n\n- If the script is not executable, run the following, where the path is to the composer executable. (If installed globally it should be in `~/.composer/vendor/bin`, otherwise it's in the folder that contains `composer.json`.)\n\n    ```bash\n    chmod +x vendor/bin/php-pre-commit\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F26b%2Fphp-pre-commit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F26b%2Fphp-pre-commit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F26b%2Fphp-pre-commit/lists"}