Skip to content

Commit

Permalink
Respect WPCS 3.0 standards in our code.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Aug 23, 2023
1 parent 71bf049 commit 8324284
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 18 deletions.
16 changes: 8 additions & 8 deletions WPForms/Sniffs/BaseSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,30 +241,30 @@ protected function getFullyQualifiedClassName( $phpcsFile ) {
*
* @since 1.0.2
*
* @param string $class Class name.
* @param string $className Class name.
*
* @return string
*/
private function convertClassName( $class ) {
private function convertClassName( $className ) {

if ( strpos( $class, '_' ) !== false ) {
return strtolower( $class );
if ( strpos( $className, '_' ) !== false ) {
return strtolower( $className );
}

return $this->camelToSnake( $class );
return $this->camelToSnake( $className );
}

/**
* Convert string from CamelCase to snake_case.
*
* @since 1.0.2
*
* @param string $string A string.
* @param string $s A string.
*
* @return string
*/
private function camelToSnake( $string ) {
private function camelToSnake( $s ) {

return strtolower( preg_replace( [ '/([a-z\d])([A-Z])/', '/([^_])([A-Z][a-z])/' ], '$1_$2', $string ) );
return strtolower( preg_replace( [ '/([a-z\d])([A-Z])/', '/([^_])([A-Z][a-z])/' ], '$1_$2', $s ) );
}
}
10 changes: 5 additions & 5 deletions WPForms/Sniffs/Comments/ParamTagHooksSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,32 +123,32 @@ private function countArguments( $phpcsFile, $stackPtr ) { // phpcs:ignore Gener

while ( $currentPosition < $lastPosition ) {
if ( $tokens[ $currentPosition ]['code'] === T_WHITESPACE ) {
$currentPosition ++;
++$currentPosition;
continue;
}

if ( $tokens[ $currentPosition ]['code'] === T_COMMA ) {
$lookingForComma = false;

$currentPosition ++;
++$currentPosition;
continue;
}

if ( in_array( $tokens[ $currentPosition ]['code'], [ T_ARRAY, T_OPEN_SHORT_ARRAY, T_CLOSURE ], true ) ) {
$quantity ++;
++$quantity;
}

if ( $this->skip( $phpcsFile, $currentPosition ) ) {
continue;
}

$currentPosition ++;
++$currentPosition;

if ( $lookingForComma ) {
continue;
}

$quantity ++;
++$quantity;

$lookingForComma = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private function getTokenNextLine( $phpcsFile, $semicolon ) {
$nextLineTokens = [];
$count = count( $tokens );

for ( $i = $semicolon; $i < $count; $i ++ ) {
for ( $i = $semicolon; $i < $count; $i++ ) {
if ( $tokens[ $i ]['line'] > $nextLine ) {
break;
}
Expand Down
8 changes: 5 additions & 3 deletions WPForms/Sniffs/Formatting/SwitchSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,15 @@ private function lineDistance( File $phpcsFile, $endPtr, $startPtr ) {
],
true
) ||
( $tokens[ $ptr ]['code'] === T_COMMENT &&
$phpcsFile->findFirstOnLine( [ T_WHITESPACE, T_COMMENT ], $ptr, true ) === false )
(
$tokens[ $ptr ]['code'] === T_COMMENT &&
$phpcsFile->findFirstOnLine( [ T_WHITESPACE, T_COMMENT ], $ptr, true ) === false
)
) {
$commentLines[] = $tokens[ $ptr ]['line'];
}

$ptr ++;
++$ptr;
}

return max(
Expand Down
2 changes: 1 addition & 1 deletion WPForms/Sniffs/PHP/BackSlashSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private function processCode( $phpcsFile, $stackPtr ) {
return;
}

$startPtr ++;
++$startPtr;

if ( $tokens[ $startPtr ]['code'] !== T_NS_SEPARATOR ) {
return;
Expand Down
1 change: 1 addition & 0 deletions WPForms/Tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ protected function process( Sniff $className, $rulesetName = '' ) {
throw new RuntimeException(
sprintf(
'The %s file does not exist',
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
$localFile
)
);
Expand Down
3 changes: 3 additions & 0 deletions WPForms/Tests/Tests/BaseSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function testGetRelativePath() {
$classFileName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'PHP_CodeSniffertemp_folder0000' . DIRECTORY_SEPARATOR . $relativePath;

if ( file_exists( $classFileName ) ) {
// phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink
unlink( $classFileName );
}

Expand Down Expand Up @@ -110,8 +111,10 @@ private function mkdirRecursive( $path ) {
}

if ( $dir !== '' && ! is_dir( $dir ) && strpos( $dir, '.' ) === false ) {
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_mkdir
mkdir( $dir );
} elseif ( ! file_exists( $dir ) && strpos( $dir, '.' ) !== false ) {
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_touch
touch( $dir );
}
}
Expand Down

0 comments on commit 8324284

Please sign in to comment.