An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

        



ptscs


» PSR-12 coding standard with additional strict rules «


[![Build](https://github.com/asispts/ptscs/actions/workflows/ci.yml/badge.svg)](https://github.com/asispts/ptscs/actions/workflows/ci.yml)
[![](https://img.shields.io/github/license/asispts/ptscs)](./LICENSE)
[![](https://img.shields.io/packagist/php-v/asispts/ptscs/dev-main)](https://github.com/asispts/ptscs)
[![](https://img.shields.io/packagist/dt/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
tests

vendor

```
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:
```xml

src/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