vishwac09/extended-php-guidelines

This package is abandoned and no longer maintained. No replacement package was suggested.

Provides set of additional coding/style guidelines to sniff PHP code.

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:phpcodesniffer-standard

1.0.0 2022-03-01 06:54 UTC

This package is auto-updated.

Last update: 2023-11-12 15:46:06 UTC


README

Apart from the PSR-1, PSR-2, PSR-12 and the Drupal standard's, we follow few more to achieve consistency of code project wide.

I work mostly on Drupal projects, so normally use the Drupal Coding standard to sniff the custom code for any violations. This PHP library is a type of PHP-CodeSniffer standard which checks PHP code against the below list.

List

  1. Order of imports - Group Drupal/Symfony imports and third party libraries added via composer separately.
  2. Avoid Switch case - PHP >= 8.0 provides match() {} expression, can be replaced in place of switch() case:.
  3. Avoid Static Class references - Cannot be injected.
  4. Order of member functions - Order member function in ascending order, improves readability.

Usage

Create a project, and add this packages as DEV dependancy.

Installation

Add via composer as local dependencies

composer require --dev dealerdirect/phpcodesniffer-composer-installer
composer require --dev vishwac09/extended-php-guidelines

OR

Add via composer as global dependencies

composer require global --dev dealerdirect/phpcodesniffer-composer-installer
composer require global --dev vishwac09/extended-php-guidelines

Add via GIT

git clone git@github.com:vishwac09/extended-php-guidelines.git

add the standard to phpcs

phpcs --config-set installed_paths /path/to/extended-php-guidelines/EPG

Run

Check if the new stanadard is configures with phpcs.

phpcs -i

Sniff code for the above violation.

phpcs --standard=EPG --colors file1.php, file2.inc

Example

FILE: /Users/hp/Documents/temp.php
------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 5 WARNINGS AFFECTING 5 LINES
------------------------------------------------------------------------------------------------------
  1 | WARNING | Group Drupal/Symfony imports and third party libraries added via composer separately.
 26 | WARNING | Member functions of class must be defined in ascending order
 28 | WARNING | Do not use static class references.
 40 | WARNING | Member functions of interface must be defined in ascending order
 50 | WARNING | Do not use switch expression. With PHP >= 8.0 use the new match expression
    |         | (https://www.php.net/manual/en/control-structures.match.php).
------------------------------------------------------------------------------------------------------