PHPackages                             loadsys/loadsys\_codesniffer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. loadsys/loadsys\_codesniffer

ActiveLibrary[Framework](/categories/framework)

loadsys/loadsys\_codesniffer
============================

Loadsys CodeSniffer Standards, uses the CakePHP core team's as a base.

3.0.8(7y ago)033.2k↓100%[6 issues](https://github.com/loadsys/loadsys_codesniffer/issues)[1 PRs](https://github.com/loadsys/loadsys_codesniffer/pulls)MITPHP

Since Apr 5Pushed 7y ago8 watchersCompare

[ Source](https://github.com/loadsys/loadsys_codesniffer)[ Packagist](https://packagist.org/packages/loadsys/loadsys_codesniffer)[ Docs](https://github.com/loadsys/loadsys_codesniffer)[ RSS](/packages/loadsys-loadsys-codesniffer/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (3)Versions (20)Used By (0)

Loadsys Code Sniffer
====================

[](#loadsys-code-sniffer)

[![Latest Version](https://camo.githubusercontent.com/21fc96b69ef35eb2485fae2fc20c29b1e3cd1be1ef2c1a5224ec5706bdc726f6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6c6f61647379732f6c6f61647379735f636f6465736e69666665722e7376673f7374796c653d666c61742d737175617265)](https://github.com/loadsys/loadsys_codesniffer/releases)[![Build Status](https://camo.githubusercontent.com/c9dfea28493dd11bb361fb1272d1183fbcd11ac34a9ffa6e8b74f20b3ced8169/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6c6f61647379732f6c6f61647379735f636f6465736e69666665722e7376673f7374796c653d666c61742d737175617265)](http://travis-ci.org/loadsys/loadsys_codesniffer)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.txt)[![Total Downloads](https://camo.githubusercontent.com/5a306a6a7cba130080e149f6f71483f4cf4a9e258449172aed3a4fe1fe5aaef1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6f61647379732f6c6f61647379735f636f6465736e69666665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/loadsys/loadsys_codesniffer)

This package works with [phpcs](http://pear.php.net/manual/en/package.php.php-codesniffer.php)and checks code against the coding standards used by Loadsys. It is based upon the [CakePHP coding standards](https://github.com/cakephp/cakephp-codesniffer) with some customizations specific to the Loadsys internal standards and preference.

⚠️ 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.

Notable Style Differences
-------------------------

[](#notable-style-differences)

This ruleset is basically [PSR-2](http://www.php-fig.org/psr/psr-2/) with the following diferences:

- 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/).)*
- 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.
- Final commas in multi-line arrays are mandatory. This makes diffs cleaner and reduces mistakes when re-ordering lists.
- All classes must be declared before use at the top of the file.

    ```
     $var = new \DateTime(); // invalid
     $var = new \Vendor\Lib(); // invalid
     $var = new Local\SubClass(); // invalid
     //---
     use \DateTime
     $var = new DateTime(); // valid
    ```

Other items that are inherited but worth pointing out anyway:

- Namespaces are mandatory for classes.
- Short array syntax is mandatory.

Installation
------------

[](#installation)

Install these code sniffs via composer in your project:

```
$ composer require loadsys/loadsys_codesniffer:~3.0
$ vendor/bin/phpcs --config-set installed_paths vendor/cakephp/cakephp-codesniffer,vendor/loadsys/loadsys_codesniffer
```

The 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.

Usage
-----

[](#usage)

Once `installed_paths` is configured, you can run phpcs using:

```
$ bin/phpcs -p --standard=Loadsys
```

*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.

A typical option is to supress warnings when running on Travis. To do so, use the `-n` CLI option.

```
$ bin/phpcs -n --standard=Loadsys
```

Contributing
------------

[](#contributing)

- Clone the project and create a new feature branch.
- Run `composer install` to install the project's testing dependencies.
- Create/edit `Loadsys/Sniffs/*` classes or modify `Loadsys/ruleset.xml` as desired.
- Add or change source files in `snifftests/files/` that verify pass/fail status for the new/changed rules.
- Run `vendor/bin/phpunit` to confirm all tests pass.
- Submit a PR.

**Note:** `phpunit` will fail to run the tests when the root directory contains a dash. (Hence **loadsys\_codesniffer** instead of **loadsys-codesniffer**).

Releasing Loadsys Code Sniffer
------------------------------

[](#releasing-loadsys-code-sniffer)

- Review and merge a PR.
- Create git tag.
- Push tag back to the repo. (Packagist will be notified.)

Testing
-------

[](#testing)

Tests 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.

These 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:

```
snifftests/files/must_not/array_syntax_long.php
snifftests/files/must/array_syntax_short_pass.php

```

Tests 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.

### Reference sniffs

[](#reference-sniffs)

Since we inherit from these rulesets, it's nice to have links to them handy:

- 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)
- 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)
- [All Squiz-provided Standards](https://github.com/squizlabs/PHP_CodeSniffer/tree/master/CodeSniffer/Standards)
- 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.)
- Codesniffer docs: [Annotated ruleset.xml](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml)

### Running codesniffs on the Loadsys-defined Sniff classes

[](#running-codesniffs-on-the-loadsys-defined-sniff-classes)

`vendor/bin/phpcs -ps --standard=snifftests/sniff_class_rules.xml Loadsys/`

This 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.

### Reviewing the rules included in the standard

[](#reviewing-the-rules-included-in-the-standard)

`vendor/bin/phpcs -e --standard=./Loadsys Loadsys`

This list can be used to help locate duplicated rules defined directly in the `Loadsys/ruleset.xml`.

### Running tests

[](#running-tests)

```
# Run once:
$ composer install
$ vendor/bin/phpcs --config-set installed_paths vendor/cakephp/cakephp-codesniffer

# Run repeatedly:
$ vendor/bin/phpunit
```

### Indicating expected sniff failures

[](#indicating-expected-sniff-failures)

All 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:

```
