{"id":19571756,"url":"https://github.com/loadsys/loadsys_codesniffer","last_synced_at":"2026-04-12T23:34:45.685Z","repository":{"id":15730512,"uuid":"18468858","full_name":"loadsys/loadsys_codesniffer","owner":"loadsys","description":"Loadsys Code Sniffer","archived":false,"fork":false,"pushed_at":"2018-09-28T19:50:54.000Z","size":349,"stargazers_count":0,"open_issues_count":7,"forks_count":0,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-04-26T06:04:40.892Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loadsys.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-05T14:50:57.000Z","updated_at":"2018-09-28T19:49:41.000Z","dependencies_parsed_at":"2022-09-10T14:20:19.646Z","dependency_job_id":null,"html_url":"https://github.com/loadsys/loadsys_codesniffer","commit_stats":null,"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsys%2Floadsys_codesniffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsys%2Floadsys_codesniffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsys%2Floadsys_codesniffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsys%2Floadsys_codesniffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loadsys","download_url":"https://codeload.github.com/loadsys/loadsys_codesniffer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240840036,"owners_count":19866164,"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":[],"created_at":"2024-11-11T06:19:56.244Z","updated_at":"2026-04-12T23:34:40.636Z","avatar_url":"https://github.com/loadsys.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Loadsys Code Sniffer\n\n[![Latest Version](https://img.shields.io/github/release/loadsys/loadsys_codesniffer.svg?style=flat-square)](https://github.com/loadsys/loadsys_codesniffer/releases)\n[![Build Status](https://img.shields.io/travis/loadsys/loadsys_codesniffer.svg?style=flat-square)](http://travis-ci.org/loadsys/loadsys_codesniffer)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.txt)\n[![Total Downloads](https://img.shields.io/packagist/dt/loadsys/loadsys_codesniffer.svg?style=flat-square)](https://packagist.org/packages/loadsys/loadsys_codesniffer)\n\nThis package works with [phpcs](http://pear.php.net/manual/en/package.php.php-codesniffer.php)\nand checks code against the coding standards used by Loadsys. It is based upon the\n[CakePHP coding standards](https://github.com/cakephp/cakephp-codesniffer) with some customizations specific to the Loadsys internal standards and preference.\n\n:warning: This code is designed to target Cake 3.x projects, for Cake 2.x projects, use one of the latests `2.x` releases of this project.\n\n\n## Notable Style Differences\n\nThis ruleset is basically [PSR-2](http://www.php-fig.org/psr/psr-2/) with the following diferences:\n\n* Tabs are used for indenting instead of spaces. When it comes to file size and typing speed, 1 character is better than 4. The other arguments for \"fine grained alignment\" are a failure of editing tools, not the tab character itself. Resorting to spaces is the wrong solution to the problem. _(See [Elastic Tabstops](http://nickgravgaard.com/elastic-tabstops/).)_\n\n* Opening braces universally go on the same line as their block opener. This applies to classes, functions, methods and all control structures. We prefer a single consistent bracing rule.\n\n* Final commas in multi-line arrays are mandatory. This makes diffs cleaner and reduces mistakes when re-ordering lists.\n\n* All classes must be declared before use at the top of the file.\n\n\t```php\n\t$var = new \\DateTime(); // invalid\n\t$var = new \\Vendor\\Lib(); // invalid\n\t$var = new Local\\SubClass(); // invalid\n\t//---\n\tuse \\DateTime\n\t$var = new DateTime(); // valid\n\t```\n\nOther items that are inherited but worth pointing out anyway:\n\n* Namespaces are mandatory for classes.\n* Short array syntax is mandatory.\n\n\n## Installation\n\nInstall these code sniffs via composer in your project:\n\n```bash\n$ composer require loadsys/loadsys_codesniffer:~3.0\n$ vendor/bin/phpcs --config-set installed_paths vendor/cakephp/cakephp-codesniffer,vendor/loadsys/loadsys_codesniffer\n```\n\nThe second command lets `phpcs` know where to find your the Loadsys and CakePHP sniffs. Ensure that you do not overwrite any existing `installed_paths` value if you have other custom PHPCS sniff locations.\n\n\n## Usage\n\nOnce `installed_paths` is configured, you can run phpcs using:\n\n```bash\n$ bin/phpcs -p --standard=Loadsys\n```\n\n*Warning* when these sniffs are installed with composer, ensure that you have configured the CodeSniffer `installed_paths` setting set for _both_ the CakePHP Standard and the Loadsys Standard.\n\nA typical option is to supress warnings when running on Travis. To do so, use the `-n` CLI option.\n\n```bash\n$ bin/phpcs -n --standard=Loadsys\n```\n\n## Contributing\n\n* Clone the project and create a new feature branch.\n* Run `composer install` to install the project's testing dependencies.\n* Create/edit `Loadsys/Sniffs/*` classes or modify `Loadsys/ruleset.xml` as desired.\n* Add or change source files in `snifftests/files/` that verify pass/fail status for the new/changed rules.\n* Run `vendor/bin/phpunit` to confirm all tests pass.\n* Submit a PR.\n\n**Note:** `phpunit` will fail to run the tests when the root directory contains a dash. (Hence **loadsys_codesniffer** instead of **loadsys-codesniffer**).\n\n\n## Releasing Loadsys Code Sniffer\n\n* Review and merge a PR.\n* Create git tag.\n* Push tag back to the repo. (Packagist will be notified.)\n\n\n## Testing\n\nTests are run on the coding standard using sample files that are designed to either pass the full sniff suite without generating any errors or warnings, or that are intended to fail and trigger _specific_ sniff errors/warnings.\n\nThese sample files live in the `snifftests/files/` directory and can be grouped in any manner that makes sense. Our choice is to group tests into two imperative folders, `must/` and `must_not/`. File names start with the topic being tested, such as `array_` or `braces_` or `indent_` and continue with more specificity. For example:\n\n```\nsnifftests/files/must_not/array_syntax_long.php\nsnifftests/files/must/array_syntax_short_pass.php\n```\n\nTests can affirm either that a coding mistake is properly caught by the sniffer, or that valid coding practices are not incorrectly caught by the sniffer.\n\n\n### Reference sniffs\n\nSince we inherit from these rulesets, it's nice to have links to them handy:\n\n* CakePHP: [ruleset.xml](https://github.com/cakephp/cakephp-codesniffer/blob/master/CakePHP/ruleset.xml), [Sniffs](https://github.com/cakephp/cakephp-codesniffer/tree/master/CakePHP/Sniffs)\n* PSR-2: [ruleset.xml](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/PSR2/ruleset.xml), [Sniffs](https://github.com/squizlabs/PHP_CodeSniffer/tree/master/CodeSniffer/Standards/PSR2/Sniffs)\n* [All Squiz-provided Standards](https://github.com/squizlabs/PHP_CodeSniffer/tree/master/CodeSniffer/Standards)\n* Vanilla Forums: [ruleset.xml](https://github.com/vanilla/addons/blob/master/standards/Vanilla/ruleset.xml), [Sniffs](https://github.com/vanilla/addons/tree/master/standards/Vanilla/Sniffs) (we use a copy of their \"ValidClassBrackets\" sniff.)\n* Codesniffer docs: [Annotated ruleset.xml](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml)\n\n\n### Running codesniffs on the Loadsys-defined Sniff classes\n\n`vendor/bin/phpcs -ps --standard=snifftests/sniff_class_rules.xml Loadsys/`\n\nThis custom ruleset relaxes a few of our normal rules to accommodate shortcomings in PHPCS's requirements for Sniff classes themselves (such as not supporting namepspaces or CamelCased class names.) The ruleset will run the entire Loadsys standard with those rules excluded.\n\n\n### Reviewing the rules included in the standard\n\n`vendor/bin/phpcs -e --standard=./Loadsys Loadsys`\n\nThis list can be used to help locate duplicated rules defined directly in the `Loadsys/ruleset.xml`.\n\n\n### Running tests\n\n```shell\n# Run once:\n$ composer install\n$ vendor/bin/phpcs --config-set installed_paths vendor/cakephp/cakephp-codesniffer\n\n# Run repeatedly:\n$ vendor/bin/phpunit\n```\n\n\n### Indicating expected sniff failures\n\nAll files inside of the `snifftests/files/` directory that do not end in `pass.php` are expected to fail at least one code sniff. The names of the sniffs that are expected to fail must be annotated on the first line of the file, like so:\n\n```php\n\t\t\u003c?php //~Standard.Section.Sniff.Rule,Second.Rule.To.Expect\n\t\t$a = [1 , 2]; // Error: Space before comma.\n```\n\nThe test suite will throw an assertion failure for any files lacking `*pass.php` that also fail to define the expected sniff failures as demonstrated above.\n\nEvery attempt should be made to restrict each sample file that is expected to fail to triggering only a single sniff. (A current shortcoming of the testing approach is that we can verify that the named sniffs fail, but can not verify that no other sniffs were also thrown in the process.)\n\n\n### Indicating expected sniff passes\n\nFiles suffixed with `pass.php` will be expected to pass all sniffs. They must **not** define any expected sniff names as failures on the first line of their contents using the `\u003c?php //~` syntax, otherwise a PHPUnit assertion will be thrown and halt the entire test suite.\n\nPositive verification tests are especially important when making modifications to the coding standard's ruleset. This prevents accidentally starting to disallow something that was previously acceptable by having an example of that \"acceptable\" behavior verified.\n\n\n### Manually reviewing tests/rules\n\nTo test a single sample file, run:\n\n```php\n$ vendor/bin/phpcs -ps --standard=./Loadsys snifftests/files/sample_file_name.php\n```\n\nTo confirm that all test files that **should** pass **do** pass, run:\n\n```php\n$ find snifftests/files -type f -name '*pass.php' -exec vendor/bin/phpcs -p --standard=./Loadsys {} +\n```\n\nTo confirm that all files that should fail, do fail, run:\n\n```php\n$ find snifftests/files -type f -name '*.php' ! -name '*pass.php' -exec vendor/bin/phpcs -p --standard=./Loadsys {} +\n```\n\nEvery file listed in should throw at least one warning or error each. (Pay attention to any `.`s in the initial progress indicator since that indicates a fully-passing file that should be failing something!) The errors listed will need to be verified by hand that they correctly match the errors that particular file _should_ be triggering.\n\n\n## License\n\n[MIT](https://github.com/loadsys/loadsys_codesniffer/blob/master/LICENSE.md)\n\n\n## Copyright\n\n[Loadsys Web Strategies](http://www.loadsys.com) 2016\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floadsys%2Floadsys_codesniffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floadsys%2Floadsys_codesniffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floadsys%2Floadsys_codesniffer/lists"}