https://github.com/asispts/ptscs
PSR-12 coding standard with additional strict rules
https://github.com/asispts/ptscs
coding-standard coding-style php phpcs-standard psr-12
Last synced: 3 months ago
JSON representation
PSR-12 coding standard with additional strict rules
- Host: GitHub
- URL: https://github.com/asispts/ptscs
- Owner: asispts
- License: mit
- Created: 2022-06-24T23:15:33.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-10T14:13:11.000Z (over 1 year ago)
- Last Synced: 2025-04-09T12:38:37.978Z (3 months ago)
- Topics: coding-standard, coding-style, php, phpcs-standard, psr-12
- Language: PHP
- Homepage: https://packagist.org/packages/asispts/ptscs
- Size: 229 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
ptscs
» PSR-12 coding standard with additional strict rules «
[](https://github.com/asispts/ptscs/actions/workflows/ci.yml)
[](./LICENSE)
[](https://github.com/asispts/ptscs)
[](https://packagist.org/packages/asispts/ptscs)[Installation](#installation) ✦
[Usage](#usage) ✦
[Notable coding standard](#notable-coding-standard) ✦
[Contributing](#contributing) ✦
[License](#license)
`ptscs` is a coding standard for [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) that follows the PSR-12 with additional strict rules. It is intended to help developers maintain consistency and readability in their codebase, and to encourage best practices.
## Installation
You can install with composer
```
composer require --dev asispts/ptscs
```## Usage
Once installed, you can create a `phpcs.xml.dist` file to define your PHPCS configuration and then configure your text editor or workflow to lint or fix the codebase based on this configuration. Here is an example phpcs.xml.dist file:
```xml
src
testsvendor
```
You can use `phpcs` to validate your source code against this standard or `phpcbf` to automatically fix any violations.To run `phpcs`, execute the following command:
```
vendor/bin/phpcs
```
To automatically fix any coding standard violations, execute the following command:
```
vendor/bin/phpcbf
```### Excluding Some Rules
You can exclude some rules by modifying the `phpcs.xml.dist` file. For example, if you want to exclude the rule that requires classes to be declared as either `final` or `abstract` in the `src/Entity` directory of a Symfony project, you can add the following to your `phpcs.xml.dist` file:
```xmlsrc/Entity
```
This will exclude the `RequireAbstractOrFinal` rule for the `src/Entity` directory. You can customize the rule and the directory as per your needs. By excluding some rules, you can customize the coding standard to better suit your project's requirements.
## Notable coding standard
As mentioned, this coding standard use PSR-12 with some exceptions and additional strict rules. Here are some notable additional strict rules.1. We exclude some PSR-12 rules to allow `declare(strict_types=1)` on the same line as PHP open tag.
```php