diff --git a/CHANGELOG.md b/CHANGELOG.md index 82ad1cb..93b4111 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All notable changes to this project will be documented in this file and formatted via [this recommendation](https://keepachangelog.com/). +## [1.4.0] - 2024-12-20 +### Changed +- ReturnTagHooksSniff is removed. + ## [1.3.0] - 2024-12-16 ### Changed - The minimum supported PHP version is now 7.1. diff --git a/WPForms/Sniffs/Comments/ReturnTagHooksSniff.php b/WPForms/Sniffs/Comments/ReturnTagHooksSniff.php deleted file mode 100644 index 889fb83..0000000 --- a/WPForms/Sniffs/Comments/ReturnTagHooksSniff.php +++ /dev/null @@ -1,168 +0,0 @@ -getTokens(); - $functionName = $tokens[ $stackPtr ]['content']; - - if ( - $tokens[ $stackPtr + 1 ]['code'] !== T_OPEN_PARENTHESIS || - ( - ! in_array( $functionName, self::FILTER_FUNCTIONS, true ) && - ! in_array( $functionName, self::ACTION_FUNCTIONS, true ) - ) - ) { - return; - } - - $commentEnd = $phpcsFile->findPrevious( T_DOC_COMMENT_CLOSE_TAG, $stackPtr - 1 ); - - if ( ! $commentEnd || $tokens[ $commentEnd ]['line'] !== $tokens[ $stackPtr ]['line'] - 1 ) { - return; - } - - $commentStart = $phpcsFile->findPrevious( T_DOC_COMMENT_OPEN_TAG, $commentEnd ); - $returnTag = $this->findTag( '@return', $commentStart, $tokens ); - - if ( in_array( $functionName, self::ACTION_FUNCTIONS, true ) ) { - $this->actionFunctionProcess( $phpcsFile, $returnTag ); - - return; - } - - $this->filterFunctionProcess( $phpcsFile, $returnTag, $stackPtr ); - } - - /** - * Process for the action functions. - * - * @since 1.0.0 - * - * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. - * @param array $returnTag Return tag information. - */ - private function actionFunctionProcess( $phpcsFile, $returnTag ) { - - if ( empty( $returnTag ) ) { - return; - } - - $phpcsFile->addError( - 'The @return tag unnecessary here.', - $returnTag['tag'], - 'UnnecessaryReturnTag' - ); - } - - /** - * Process for the filter functions. - * - * @since 1.0.0 - * - * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. - * @param array $returnTag Return tag information. - * @param int $stackPtr Function name position. - */ - public function filterFunctionProcess( $phpcsFile, $returnTag, $stackPtr ) { - - $tokens = $phpcsFile->getTokens(); - $hookNamePtr = $phpcsFile->findNext( T_CONSTANT_ENCAPSED_STRING, $stackPtr + 1 ); - $hookName = trim( $tokens[ $hookNamePtr ]['content'], '"\'' ); - - if ( empty( $returnTag ) ) { - $phpcsFile->addError( - sprintf( - 'Add the @return tag for the %s hook.', - $hookName - ), - $stackPtr, - 'AddReturnTag' - ); - - return; - } - - $commentEnd = $phpcsFile->findNext( T_DOC_COMMENT_CLOSE_TAG, $returnTag['tag'] ); - $returnType = $phpcsFile->findNext( T_DOC_COMMENT_STRING, $returnTag['tag'], $commentEnd ); - - if ( empty( $returnType ) ) { - $phpcsFile->addError( - 'Missing return type', - $returnTag['tag'], - 'MissingReturnType' - ); - - return; - } - - if ( $tokens[ $commentEnd ]['line'] !== $tokens[ $returnTag['tag'] ]['line'] + 1 ) { - $phpcsFile->addError( - 'The @return tag should be the last tag in the PHPDoc.', - $returnTag['tag'], - 'InvalidReturnTagPosition' - ); - } - } -} diff --git a/WPForms/Tests/Tests/Comments/ReturnTagHooksTest.php b/WPForms/Tests/Tests/Comments/ReturnTagHooksTest.php deleted file mode 100644 index 4371bc1..0000000 --- a/WPForms/Tests/Tests/Comments/ReturnTagHooksTest.php +++ /dev/null @@ -1,29 +0,0 @@ -process( new ReturnTagHooksSniff() ); - - $this->fileHasErrors( $phpcsFile, 'UnnecessaryReturnTag', [ 80 ] ); - $this->fileHasErrors( $phpcsFile, 'AddReturnTag', [ 106 ] ); - $this->fileHasErrors( $phpcsFile, 'MissingReturnType', [ 130 ] ); - $this->fileHasErrors( $phpcsFile, 'InvalidReturnTagPosition', [ 148 ] ); - } -}