Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shopsys/coding-standards
[READ-ONLY] Tools for automated checks of coding standards in PHP projects. Predefined rulesets included.
https://github.com/shopsys/coding-standards
Last synced: 5 days ago
JSON representation
[READ-ONLY] Tools for automated checks of coding standards in PHP projects. Predefined rulesets included.
- Host: GitHub
- URL: https://github.com/shopsys/coding-standards
- Owner: shopsys
- License: mit
- Created: 2016-04-08T08:48:24.000Z (over 8 years ago)
- Default Branch: 16.0
- Last Pushed: 2024-12-06T08:02:25.000Z (17 days ago)
- Last Synced: 2024-12-11T05:25:24.073Z (12 days ago)
- Language: PHP
- Homepage:
- Size: 449 KB
- Stars: 20
- Watchers: 11
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Shopsys Coding Standards
[![Downloads](https://img.shields.io/packagist/dt/shopsys/coding-standards.svg)](https://packagist.org/packages/shopsys/coding-standards)
Shopsys Coding Standards are based on [PSR-2](http://www.php-fig.org/psr/psr-2/).
This project bundles tools along with predefined rulesets for automated checks of Shopsys Coding Standards that we use in many Shopsys projects.
The repository also contains [few custom rules](#custom-rules).This repository is maintained by [shopsys/shopsys] monorepo, information about changes is in [monorepo CHANGELOG.md](https://github.com/shopsys/shopsys/blob/master/CHANGELOG.md).
Provided tools:
- [PHP-Parallel-Lint](https://github.com/JakubOnderka/PHP-Parallel-Lint)
- [EasyCodingStandard](https://github.com/Symplify/EasyCodingStandard) that combines [PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) and [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)For further information see official documentation of those tools.
## Installation
```bash
php composer require shopsys/coding-standards
```## Usage
Create `easy-coding-standard.yml` config file in your project which includes predefined ruleset.
You can also [customize the rules](https://github.com/shopsys/shopsys/blob/master/UPGRADE.md#shopsyscoding-standards)
and even add your own sniffs and fixers in the config.```yaml
#easy-coding-standard.yml
imports:
- { resource: '%vendor_dir%/shopsys/coding-standards/easy-coding-standard.yml' }
```In terminal, run following commands:
```bash
php vendor/bin/parallel-lint /path/to/project
php vendor/bin/ecs check /path/to/project --config=/path/to/project/custom-coding-standard.yml
```## Custom rules
### Rules for [PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer)
#### `Shopsys/missing_button_type`
All `` HTML tags in `.html` and `.html.twig` files must have explicit `type` attribute.
If the `type` is not specified it will be fixed to `type="button""` because the implicit value is `submit` which makes it behave differently based on the context (`` inside `` element submits the form).
#### `Shopsys/orm_join_column_require_nullable`
Doctrine annotations `@ORM\ManyToOne` and `@ORM\OneToOne` must have `nullable` option defined explicitly in `@ORM\JoinColumn`.
If the `nullable` option is not specified it will be fixed to `nullable=false` because the implicit value is `true` but this is the opposite to the implicit value of `nullable` for `@Column` annotation.
This makes it consistent.### Rules for [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
#### `ForbiddenExitSniff`
Function `exit()` is not allowed.
#### `ForbiddenSuperGlobalSniff`
Usage of superglobals (`$_COOKIE`, `$_GET`, `$_FILES`, `$_POST`, `$_REQUEST`, `$_SERVER`) is not allowed.
#### `ObjectIsCreatedByFactorySniff`
Instantiation of objects that can be created by their factories is not allowed outside of the factory.
#### `ValidVariableNameSniff`
Default `\PHP_CodeSniffer\Standards\Squiz\Sniffs\NamingConventions\ValidVariableNameSniff`
does not report method parameters in `$_var` format as an violation but it should.
It also skips checking of private members when `PrivateNoUnderscore` property is disabled.This sniff provides the missing functionality and is intended to be used as an addition to the default `ValidVariableNameSniff`.
## Contributing
Thank you for your contributions to Shopsys Coding Standards package.
Together we are making Shopsys Platform better.This repository is READ-ONLY.
If you want to [report issues](https://github.com/shopsys/shopsys/issues/new) and/or send [pull requests](https://github.com/shopsys/shopsys/compare),
please use the main [Shopsys repository](https://github.com/shopsys/shopsys).Please, check our [Contribution Guide](https://github.com/shopsys/shopsys/blob/master/CONTRIBUTING.md) before contributing.
## Support
What to do when you are in troubles or need some help?
The best way is to join our [Slack](https://join.slack.com/t/shopsysframework/shared_invite/zt-11wx9au4g-e5pXei73UJydHRQ7nVApAQ).If you want to [report issues](https://github.com/shopsys/shopsys/issues/new), please use the main [Shopsys repository](https://github.com/shopsys/shopsys).
[shopsys/shopsys]: (https://github.com/shopsys/shopsys)