WPForms coding standards are based on the WordPress Coding Standards and the PHPCompatibility Coding Standards and help create strict and high-quality code.

Overview

WPForms Coding Standards

Maintainers: The WPForms team

License: GPLv2 any later version.
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Description

WPForms coding standards are based on the WordPress Coding Standards and the PHPCompatibility Coding Standards and help create strict and high-quality code.

Installation

composer config repositories.repo-name vcs https://github.com/awesomemotive/wpforms-phpcs.git
composer require awesomemotive/wpforms-phpcs --dev

Configuration

Create the .phpcs.xml or phpcs.xml file at the root of your project:

The WPForms coding standard. \vendor/* \.github/* ">
xml version="1.0"?>
<ruleset name="WPForms CS">
	<description>The WPForms coding standard.description>

	<exclude-pattern>\vendor/*exclude-pattern>
	<exclude-pattern>\.github/*exclude-pattern>

	<config name="testVersion" value="5.6-"/>
	<config name="multi_domains" value="true"/>
	<config name="minimum_supported_wp_version" value="5.2"/>

	<rule ref="WPForms"/>

	<rule ref="WPForms.PHP.ValidateDomain">
		<properties>
			<property name="wpforms-lite" value="wpforms"/>
			<property name="wpforms" value="wpforms/pro/,wpforms/src/Pro/"/>
		properties>
	rule>
ruleset>

Sniffs detail

Validate Text Domain Sniff

The WPForms.PHP.ValidateDomain sniff validates that you are using the correct text domain for i18n functions such as __(), _e(), _n(), etc.

By default, this sniff works for one domain in the project. We get a directory name based on the vendor directory or the location of the phpcs.xml/.phpcs.xml file.

You can install our package to the plugins directory and enable the multi-domain mode. in this case, the text domain will be the next folder name in the path. Structure:

../wp-content/plugins/          # → Root
├── wpforms/                    # → `wpforms` domain.
└── wpforms-stripe/             # → `wpforms-stripe` domain.

In your config you should enable the multi_domains property:

">
xml version="1.0"?>
<ruleset name="WPForms CS">
	
	<config name="multi_domains" value="true"/>
	
ruleset>

If you have different domains for directories inside your project (for example, for free and paid versions) and want to redefine the text domain for some paths:

../wp-content/plugins/          # → Root
├── wpforms/                    # → `wpforms-lite` domain.
│   ├── pro/                    # → `wpforms` domain.
│   └── src/                    # → `wpforms-lite` domain.
│       ├── Admin/              # → `wpforms-lite` domain.
│       └── Pro/                # → `wpforms` domain.
└── wpforms-stripe/             # → `wpforms-stripe` domain.

In this case, you should add to the config file the property with name as a text domain and value as a path. If a domain has several paths, then list them via commas.

">
xml version="1.0"?>
<ruleset name="WPForms CS">
	
	<config name="multi_domains" value="true"/>
	<rule ref="WPForms.PHP.ValidateDomain">
		<properties>
			<property name="wpforms-lite" value="wpforms"/>
			<property name="wpforms" value="wpforms/pro/,wpforms/src/Pro/"/>
		properties>
	rule>
	
ruleset>
Comments
  • Language injections sniff

    Language injections sniff

    Description

    Some sniffs are triggered in specific cases that should be excluded. I'll update the list during further testing.

    • PhpStorm's language injection comment /** @lang <Language> */ triggers Generic.Commenting.DocComment.MissingShort
    • PhpStorm's language injection comment // language=<Language> triggers Squiz.Commenting.InlineComment.InvalidEndChar

    I have added a new sniff that checks the two language injections mentioned above and blocks the raising relevant errors by another sniff. It required a lot of debugging, however. No examples on the Internet, no such cases in our code.

    I have added a simple test for it, which also required a lot of debugging, as we need to use not only the sniff tested but also standard sniffs (in which we have to block raising the error).

    Motivation and Context

    Fixes #13.

    Testing procedure

    PHPUnit tests.

    opened by kagg-design 13
  • Exclusions to some generic sniffs

    Exclusions to some generic sniffs

    Some sniffs are triggered in specific cases that should be excluded. I'll update the list during further testing.

    • [ ] PhpStorm's language injection comment /** @lang <Language> */ triggers Generic.Commenting.DocComment.MissingShort

    More exclusions may be added later...

    enhancement 
    opened by ihorvorotnov 1
  • Beautify switch statements

    Beautify switch statements

    Description

    Add next rules for the switch statement:

    • [ ] An empty line before the switch statement
    • [ ] An empty line after the switch statement (if it no last)
    • [ ] An empty line before the case or default statement (if it no first)
    • [ ] No empty line before the break statement.

    Tested code

    Correct:

    function example( $args ) {
    
    	switch ( $args['value_compare'] ) {
    		case 'is':
    			$where['arg_value'] = "{$fields_table}.value = ''";
    			break;
    
    		case 'is_not':
    			$where['arg_value'] = "{$fields_table}.value <> ''";
    			break;
    	}
    }
    
    feature 
    opened by wppunk 1
  • Domain check for i18n function work isn't correctly for multi domain project

    Domain check for i18n function work isn't correctly for multi domain project

    Description

    I added a directory separator at the end of domains & file dir.

    Motivation and Context

    Fixes #23.

    Testing procedure

    1. Set up config:
    <config name="multi_domains" value="true"/>
    <rule ref="WPForms.PHP.ValidateDomain">
        <properties>
            <property name="wpforms-lite" value="wpforms"/>
            <property name="wpforms" value="wpforms/pro/,wpforms/src/Pro/"/>
        </properties>
    </rule>
    
    1. Create a file wpforms-some-addon-name/some-directory/some-file.php
    2. Add in the file a few i18n functions
    3. Run the code sniffer
    • [ ] I added a test file to WPForms/Tests/TestFiles/
    • [ ] I added a unit tests
    opened by wppunk 0
  • Domain check for i18n function work isn't correctly for multi domain config

    Domain check for i18n function work isn't correctly for multi domain config

    Expected Behavior

    i18n functions for the file wpforms-some-addon-name/some-directory/some-file.php should have the wpforms-some-addon domain.

    Current Behavior

    Config:

    <config name="multi_domains" value="true"/>
    <rule ref="WPForms.PHP.ValidateDomain">
        <properties>
            <property name="wpforms-lite" value="wpforms"/>
            <property name="wpforms" value="wpforms/pro/,wpforms/src/Pro/"/>
        </properties>
    </rule>
    

    i18n functions for the file wpforms-some-addon-name/some-directory/some-file.php have the wpforms-lite domain.

    Possible Solution

    We should fix the algorithm for detecting rewritten domains. Fix the findDomainByProperty method by adding an additional slash at the end.

    Steps to Reproduce

    1. Set up config:
    <config name="multi_domains" value="true"/>
    <rule ref="WPForms.PHP.ValidateDomain">
        <properties>
            <property name="wpforms-lite" value="wpforms"/>
            <property name="wpforms" value="wpforms/pro/,wpforms/src/Pro/"/>
        </properties>
    </rule>
    
    1. Create a file wpforms-some-addon-name/some-directory/some-file.php
    2. Add in the file a few i18n functions
    3. Run the code sniffer
    bug 
    opened by wppunk 0
  • Fixed hooks name convention

    Fixed hooks name convention

    Description

    I updated the hook name convention due to the documentation.

    Motivation and Context

    Testing procedure

    • [x] I added a test file to WPForms/Tests/TestFiles/
    • [x] I added a unit tests
    opened by wppunk 0
  • Remove requirement for a new line before break statement inside the switch.

    Remove requirement for a new line before break statement inside the switch.

    Description

    Remove requirement for a new line before break statement inside the switch. Keep requirement for empty line after assignment before the break if foreach.

    Motivation and Context

    Fixes #20.

    Testing procedure

    • [x] I added a test file to WPForms/Tests/TestFiles/
    • [x] I added a unit tests
    opened by kagg-design 0
  • Suggestion: remove requirement for a new line before break statement inside the switch

    Suggestion: remove requirement for a new line before break statement inside the switch

    Expected Behavior

    The switch statement is already nicely formatted by default, break; is on the last line inside the case section most of the time. I would like to be able to save some space and not bloat the easily readable code with an extra new line requirement we currently have in effect. So I propose to allow this:

    switch( $foo ) {
    	case 'foo':
    		$bar = 1;
    		break;
    
    	case 'bar':
    		$bar = 2;
    		break;
    
    	case 'baz':
    		$bar = 3;
    		break;
    
    	case 'krya':
    	default:
    		$bar = 4;
    }
    

    Current Behavior

    Right now wpforms-phpcs insists on having a new line before break, which looks like this:

    switch( $foo ) {
    	case 'foo':
    		$bar = 1;
    
    		break;
    
    	case 'bar':
    		$bar = 2;
    
    		break;
    
    	case 'baz':
    		$bar = 3;
    
    		break;
    
    	case 'krya':
    	default:
    		$bar = 4;
    }
    

    It has been mentioned here #8, but not implemented.

    enhancement 
    opened by slaFFik 0
  • Fix relative path detection in PhpStorm temporary folder.

    Fix relative path detection in PhpStorm temporary folder.

    Description

    We use relative path detection in ValidateDomain and ValidateHooks sniffs. It works well when we run phpcs as a standalone process. However, in PhpStorm the relative path was detected improperly, providing the following distorted messages:

    Screenshot_2

    This happed because PhpStorm runs phpcs on a copy of the PHP file, located in the temp folder. The current fix provides processing of this special case.

    Testing procedure

    Open any old file having hooks not by the current standard, for instance, wp-content/plugins/wpforms/includes/class-frontend.php:1416. Hover on the line 1416:

    $captcha_inline = apply_filters( 'wpforms_frontend_captcha_inline_script', $this->get_captcha_inline_script( $captcha_settings ) );
    

    Make sure that popup message in PhpStorm is: "phpcs: WPForms.PHP.ValidateHooks.InvalidHookName: The wpforms_frontend_captcha_inline_script is invalid hook name. The hook name should start with wpforms_includes_class-frontend."

    opened by kagg-design 0
  • Merge ruleset with the currently used version

    Merge ruleset with the currently used version

    Merge ruleset with the currently used version of the WPForms CS in the wpforms-plugin repository.

    Description

    The currently used ruleset in the WPForms plugin is a bit more advanced. We have to merge rulesets into this repository.

    opened by kagg-design 0
  • Fix readme

    Fix readme

    Description

    Fix readme.md, composer.json, license

    Motivation and Context

    The files mentioned above had some issues. Readme.md - with the English language, MIT license is not appropriate for WordPress and was replaced by GNU-2. The same was fixed in composer.json, along with some polishing.

    opened by kagg-design 0
  • Multiple @throws do not have the same formatting rules as @param

    Multiple @throws do not have the same formatting rules as @param

    Consider this snippet:

     * @param string $email     The subscriber's current email address.
     * @param string $new_email The subscriber's new email address.
     *
     * @throws ResponseException Invalid response.
     * @throws RequiredArgumentMissingException Required argument is missing.
    

    It looks inconsistent in the same phpdoc where we enforce special formatting for @param. I think this looks better:

     * @param string $email     The subscriber's current email address.
     * @param string $new_email The subscriber's new email address.
     *
     * @throws ResponseException                Invalid response.
     * @throws RequiredArgumentMissingException Required argument is missing.
    
    enhancement 
    opened by slaFFik 0
  • Known issues

    Known issues

    Expected Behavior

    There are several issues found upon commencement of repo usage with the WPForms plugins.

    Current Behavior

    • [x] Endless loop in ParamTagHooksSniff::countArguments. Fixed in 51d941e5bca2361ba72f9822c59476cfd903805f.
    • [x] Relative path detection in PhpStorm temporary folder. Fixed in #18.
    • [x] Do not scan vendor folders in plugins. Fixed in 133a6fe99f31acf64ff54139189dd6fbf7d0933a.
    • [x] Fix determining the fully qualified class name (FQCN) to validate hook name. We determined the FQCN from the file path, which doesn't work at all for classes not following the PSR-4 standard. I have created the FQCN extraction from analyzed file tokens. Fixed in f7eb0778bf5ed7945c1da53cf3b47e09510ec13a.
    • [x] Reduce usage of @runInSeparateProcess in tests. Fixed in 05eb4391687e1fecd0c7a7490d80785736a32961.
    • [x] Validation of the text domain has some issues: when the domain is not specified, last argument of the i18n function is not a string, i18n function contains nested parenthesis. Fixed in a59d5f59e5347ec5a7ed865fbafe31e51515e030.
    • [x] In hook expected names, convert class name from CamelCase to snake_case. Fixed in c60c67ba8ecc71b0bbd36fbf5d429898178a6fff.
    • [x] Cannot detect the hook name when a hook is not a constant string. Fixed in ea81cafd195a72b376e0905129c956574ee1e3cb and d2300f27bf33c35af386091a63a032c601316494.
    • [x] Allow the presence of comments inside the first argument (hook name). Fixed in 0f5577b1cac49748fedc68cfb5a2c03bc1ccbff9.
    • [x] Adding of the multi_domains setting to the phpcs.xml blocks detection of the WordPress.Security.NonceVerification.Recommended, For instance, in wp-content/plugins/wpforms/wpforms.php:217. Fixed by a commit above.
    • [x] Message phpcs: WPForms.PHP.ValidateDomain.InvalidDomain: You are using invalid domain name. Use wpforms instead of wpforms-lite appears on many files. Fixed in d973e799dc20432b243dbee55d692770ddaae170.
    • [x] Message Remove unneededusestatement (WPForms.PHP.UseStatement.UnusedUseStatement) is wrong when class is used in PHPDoc only. See TestCase,php as an example. The problem was in ignoring @throws statements. Fixed in 389b5598f569ccafc4dee61ffd87e6675d92641f.
    • [x] Message phpcs: WPForms.Formatting.EmptyLineBeforeReturn.RemoveEmptyLineBeforeReturnStatement: Remove empty line before return statement in xxx line. occurs when if contains a comment line and the return statement only. Fixed in 3130c0c48e7d30d2d07708650748eeb41c0fa5c5.
    • [x] Endless loop in SinceTagHooksSniff.php. Fixed in e212b300b396e45dfdcaf3e0a29cdd53b29f5887.
    • [x] Wrong detection of the text domain by the property in the ruleset. Fixed in 9ae857bbbadf1fb4fb21b5673ab4a66fea153b3f.
    • [x] Prevent endless loop in HooksMethoidSniff.php. Fixed in a0555813132735799fed2ad1fe6609e552ebf346.
    • [x] Do not use HooksMethodSniff.php when not in the class file. Fixed in e7dcf55edabf64234dbdc9257fc00e4bd41041ad.
    • [x] Fix wrong @param tag counting when a hook has no arguments. Fixed in 449b1e2c2b156de6540b22df0763d48bbd60564a.
    • [x] In wpforms/includes/class-frontend.php the statement apply_filters( 'wpforms_amp_pro', wpforms()->is_pro() ) requires 3 @param tags. - Fixed in 72bbd6750dc3602e072646f8b8d5c45507b31b12.
    • [x] In \WPFormsSurveys\Loader::init we improperly claim WPForms.PHP.BackSlash.UseShortSyntax. Fixed in 66dd8ef8f7971007795f482dfb509fc3655889c4.
    • [x] Respect /** This action/filter is documented in... */ and do not count @param tags.. Fixed in 56a6c5ddabcdbfbd520127a704621a17b3e04275.
    • [ ] Wrong counting of nested @param tags (screenshot)
    • [ ] Improperly claim WPForms.Comments.PHPDocHooks.RequiredHookDocumentation (screenshot1, screenshot2)
    • [ ] WPForms.Comments.PHPDocDefine.MissPHPDoc reported on test files, what is not expected
    • [x] When @param uses [], like WP_Post[], the alignment error ParamTagHooks.InvalidAlign occurs
    • [x] phpcs: WPForms.Formatting.Switch.AddEmptyLineBefore: You should add an empty line before on wp-content/plugins/wpforms/includes/admin/builder/functions.php:106 looks like incomplete message.
    • [ ] Hooks can only be added in thehooksmethod on wp-content/plugins/wpforms/includes/admin/builder/class-builder.php:92 is repeated several times in CLI mode.
    • [x] Incorrectly calculating hook's arguments for the apply_filters_deprecated and do_action_deprecated functions.
    • [x] Shouldn't be errors related to the Hooks Documentation when a hook has a comment /** This filter(action) is documented in path/to/file */
    • [x] Hooks in addons should start with wpform_addon_name. Fixed in d64997fe3582b36215b860f264dc360158b52a15.
    • [x] All namespace parts consisting of two or more words in hook names should be converted to snake case and has underscore symbol between words: e.g. WPForms\LongNameSpacePart\LongClassName -> wpforms_long_name_space_part_long_class_name_
    • [x] If a namespace part the same as a class name we should collapse them: e.g. WPForms\Providers\Provides -> wpforms_providers_
    • [ ] Message Remove unneeded use statement (WPForms.PHP.UseStatement.UnusedUseStatement) is wrong when class is used in PHPDoc only. The problem was in ignoring @return statements.
    • [x] Cannot define text domain in the same directory where phpcs.xml is located. So, <property name="wp-mail-smtp" value="." /> does not work. Fixed in 6ee0896af1dbd3e6a38f9d5e3ba6009541b59ece.
    • [ ] Show an error if the i18n function doesn't have a domain at all.
    bug 
    opened by kagg-design 0
Owner
Awesome Motive, Inc.
We're Technically Awesome
Awesome Motive, Inc.
⚗️ Adds code analysis to Laravel improving developer productivity and code quality.

⚗️ About Larastan Larastan was created by Can Vural and Nuno Maduro, got artwork designed by @Caneco, is maintained by Can Vural, Nuno Maduro, and Vik

Nuno Maduro 4.4k Jan 4, 2023
PHP package to make your objects strict and throw exception when you try to access or set some undefined property in your objects.

?? Yell PHP package to make your objects strict and throw exception when you try to access or set some undefined property in your objects. Requirement

Zeeshan Ahmad 20 Dec 8, 2018
Leaf's very own high-speed, high-performance server

[WIP] Leaf Eien Server Eien is Leaf's implementation of a high-speed, high-performance server based on powerful tools like Open Swoole and Swoole. Eie

Leaf Framework 8 Dec 28, 2022
PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.

PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.

Squiz Labs 9.9k Jan 5, 2023
A tool to automatically fix Twig Coding Standards issues

Twig CS Fixer Installation This standard can be installed with the Composer dependency manager. Add the coding standard as a dependency of your projec

Vincent Langlet 50 Jan 6, 2023
Composer installer for PHP_CodeSniffer coding standards

PHP_CodeSniffer Standards Composer Installer Plugin This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards (r

Dealerdirect 462 Dec 22, 2022
This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards

PHP_CodeSniffer Standards Composer Installer Plugin This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards (r

PHPCSStandards 393 Feb 25, 2022
A tool to automatically fix PHP Coding Standards issues

PHP Coding Standards Fixer The PHP Coding Standards Fixer (PHP CS Fixer) tool fixes your code to follow standards; whether you want to follow PHP codi

null 11.6k Jan 1, 2023
Enhance product data quality and streamline content creation with the Pimcore and ChatGPT integration.

chatgpt-pimcore Enhance product data quality and streamline content creation with the Pimcore and ChatGPT integration. Overview The integration of Pim

Pravin chaudhary 6 Jun 5, 2023
PHP_Depend is an adaptation of the established Java development tool JDepend. This tool shows you the quality of your design in terms of extensibility, reusability and maintainability.

PHP Depend Documentation PHP Depend for enterprise Available as part of the Tidelift Subscription. The maintainers of PHP Depend and thousands of othe

PHP_Depend 837 Dec 14, 2022
Install an execute script of specify quality tools to your git pre-commit hook, and it executes only for changed files

Quality Hook Installer Install an execute script of specify quality tools to your git pre-commit hook, and it executes only for changed files Install

Kay W. 2 Dec 15, 2022
Internal Quality Assurance Cell, IQAC Project Data Capturing System.

IQAC-DCS-2021 Added AQAR Directory with template pages! Old Readme Internal Quality Assurance Cell, IQAC Project Data Capturing System. Fork Repo Clon

Kashif Raza 4 Jan 4, 2022
This package provides a wrapper for Google Lighthouse to audit the quality of web pages with Laravel.

laravel-google-lighthouse This package is based on octoper/lighthouse-php. This package provides a wrapper for Google Lighthouse to audit the quality

Logiek 5 Jun 1, 2022
Comprehensive Plugin for composer to execute PHP Quality assurance Tools

NOT MAINTANED ANYMORE The development of composer-plugin-qa was dropped in favor of phpqa which is actively maintained. The project use docker and can

Webysther Nunes 25 Apr 30, 2021
Documentation on clean coding and demonstration of studied clean coding principals with PHP.

practice-php-clean-code Documentation on clean coding and demonstration of studied clean coding principals with PHP. The document contained in this re

Ferdous Islam 1 Feb 21, 2022
Coding-standard - Magento PHP CodeSniffer Coding Standard

ECG Magento Code Sniffer Coding Standard ECG Magento Code Sniffer Coding Standard is a set of rules and sniffs for PHP_CodeSniffer tool. It allows aut

Magento ECG 309 Jan 3, 2023
A composer package designed to help you create a JSON:API in Phalcon

phalcon-json-api-package A composer package designed to help you create a JSON:API in Phalcon What happens when a PHP developer wants to create an API

Jim 36 Oct 7, 2022
Tars is a high-performance RPC framework based on name service and Tars protocol, also integrated administration platform, and implemented hosting-service via flexible schedule.

TARS - A Linux Foundation Project TARS Foundation Official Website TARS Project Official Website WeChat Group: TARS01 WeChat Offical Account: TarsClou

THE TARS FOUNDATION PROJECTS 9.6k Jan 1, 2023
A library of powerful code snippets to help you get the job done with Gravity Forms and Gravity Perks.

Gravity Wiz Snippet Library Gravity Wiz is creating the most comprehensive library of snippets for Gravity Forms ever. We'll be consistently moving ou

Gravity Wiz 151 Dec 27, 2022