Skip to content

Commit

Permalink
Consistent class exists check for extended classes.
Browse files Browse the repository at this point in the history
Ensure that any sniff with a dependency on an external sniff has a consistent `class_exists()` check and throws an appropriate error message.
  • Loading branch information
jrfnl committed Jul 29, 2016
1 parent 9d0d32d commit de73645
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions WordPress/Sniffs/Arrays/ArrayDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* @author Marc McIntyre <[email protected]>
*/

if ( ! class_exists( 'Squiz_Sniffs_Arrays_ArrayDeclarationSniff', true ) ) {
throw new PHP_CodeSniffer_Exception( 'Class Squiz_Sniffs_Arrays_ArrayDeclarationSniff not found' );
}

/**
* Enforces WordPress array format.
*
Expand Down
4 changes: 4 additions & 0 deletions WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* @author John Godley <[email protected]>
*/

if ( ! class_exists( 'PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff', true ) ) {
throw new PHP_CodeSniffer_Exception( 'Class PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff not found' );
}

/**
* Enforces WordPress function name and method name format, based upon Squiz code.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @link http://pear.php.net/package/PHP_CodeSniffer
*/

if ( class_exists( 'PHP_CodeSniffer_Standards_AbstractVariableSniff', true ) === false ) {
if ( ! class_exists( 'PHP_CodeSniffer_Standards_AbstractVariableSniff', true ) ) {
throw new PHP_CodeSniffer_Exception( 'Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found' );
}

Expand Down
2 changes: 1 addition & 1 deletion WordPress/Sniffs/PHP/DiscouragedFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author John Godley <[email protected]>
*/

if ( false === class_exists( 'Generic_Sniffs_PHP_ForbiddenFunctionsSniff', true ) ) {
if ( ! class_exists( 'Generic_Sniffs_PHP_ForbiddenFunctionsSniff', true ) ) {
throw new PHP_CodeSniffer_Exception( 'Class Generic_Sniffs_PHP_ForbiddenFunctionsSniff not found' );
}

Expand Down
4 changes: 4 additions & 0 deletions WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/
*/

if ( ! class_exists( 'Generic_Sniffs_PHP_ForbiddenFunctionsSniff', true ) ) {
throw new PHP_CodeSniffer_Exception( 'Class Generic_Sniffs_PHP_ForbiddenFunctionsSniff not found' );
}

/**
* Disallow Filesystem writes.
*
Expand Down
4 changes: 4 additions & 0 deletions WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/
*/

if ( ! class_exists( 'Generic_Sniffs_PHP_ForbiddenFunctionsSniff', true ) ) {
throw new PHP_CodeSniffer_Exception( 'Class Generic_Sniffs_PHP_ForbiddenFunctionsSniff not found' );
}

/**
* WordPress_Sniffs_VIP_SessionFunctionsUsageSniff.
*
Expand Down
4 changes: 4 additions & 0 deletions WordPress/Sniffs/VIP/SessionVariableUsageSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/
*/

if ( ! class_exists( 'Generic_Sniffs_PHP_ForbiddenFunctionsSniff', true ) ) {
throw new PHP_CodeSniffer_Exception( 'Class Generic_Sniffs_PHP_ForbiddenFunctionsSniff not found' );
}

/**
* WordPress_Sniffs_VIP_SessionVariableUsageSniff
*
Expand Down
4 changes: 4 additions & 0 deletions WordPress/Sniffs/VIP/TimezoneChangeSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/
*/

if ( ! class_exists( 'Generic_Sniffs_PHP_ForbiddenFunctionsSniff', true ) ) {
throw new PHP_CodeSniffer_Exception( 'Class Generic_Sniffs_PHP_ForbiddenFunctionsSniff not found' );
}

/**
* WordPress_Sniffs_VIP_TimezoneChangeSniff.
*
Expand Down

0 comments on commit de73645

Please sign in to comment.