Repository navigation
Add return types to private sniff methods #901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,7 +100,7 @@ public function process_token( $stackPtr ) { | |
| * | ||
| * @return void | ||
| */ | ||
| private function processArray( $stackPtr ) { | ||
| private function processArray( $stackPtr ): void { | ||
|
|
||
| $open_close = Arrays::getOpenClose( $this->phpcsFile, $stackPtr ); | ||
| if ( $open_close === false ) { | ||
|
|
@@ -135,7 +135,7 @@ private function processArray( $stackPtr ) { | |
| * | ||
| * @return void | ||
| */ | ||
| private function processString( $stackPtr, $start = 0, $end = null ) { | ||
| private function processString( $stackPtr, $start = 0, $end = null ): void { | ||
|
|
||
| $callbackFunctionName = TextStrings::stripQuotes( $this->tokens[ $stackPtr ]['content'] ); | ||
|
|
||
|
|
@@ -164,7 +164,7 @@ private function processString( $stackPtr, $start = 0, $end = null ) { | |
| * | ||
| * @return void | ||
| */ | ||
| private function processFunction( $stackPtr, $start = 0, $end = null ) { | ||
| private function processFunction( $stackPtr, $start = 0, $end = null ): void { | ||
|
|
||
| $functionName = $this->tokens[ $stackPtr ]['content']; | ||
|
|
||
|
|
@@ -187,7 +187,7 @@ private function processFunction( $stackPtr, $start = 0, $end = null ) { | |
| * | ||
| * @return void | ||
| */ | ||
| private function processFunctionBody( $stackPtr ) { | ||
| private function processFunctionBody( $stackPtr ): void { | ||
|
|
||
| $filterName = $this->tokens[ $this->filterNamePtr ]['content']; | ||
|
|
||
|
|
@@ -265,7 +265,7 @@ private function processFunctionBody( $stackPtr ) { | |
| * | ||
| * @return bool | ||
| */ | ||
| private function isInsideIfConditonal( $stackPtr ) { | ||
| private function isInsideIfConditonal( $stackPtr ): bool { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, not from this PR, just something I noticed in passing: the two
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I'll leave it for a separate PR so this one stays about return types |
||
|
|
||
| // This check helps us in situations a class or a function is wrapped | ||
| // inside a conditional as a whole. Eg.: inside `class_exists`. | ||
|
|
@@ -302,7 +302,7 @@ private function isInsideIfConditonal( $stackPtr ) { | |
| * | ||
| * @return bool | ||
| */ | ||
| private function hasTerminatingStatement( $scopeStart, $scopeEnd ) { | ||
| private function hasTerminatingStatement( $scopeStart, $scopeEnd ): bool { | ||
|
|
||
| $terminatingPtr = $this->phpcsFile->findNext( | ||
| [ T_EXIT, T_THROW ], | ||
|
|
@@ -320,7 +320,7 @@ private function hasTerminatingStatement( $scopeStart, $scopeEnd ) { | |
| * | ||
| * @return bool | ||
| **/ | ||
| private function isReturningVoid( $stackPtr ) { | ||
| private function isReturningVoid( $stackPtr ): bool { | ||
|
|
||
| $nextToReturnTokenPtr = $this->phpcsFile->findNext( | ||
| Tokens::$emptyTokens, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,7 +96,7 @@ public function process_token( $stackPtr ) { | |
| * | ||
| * @return void | ||
| */ | ||
| private function processArray( $stackPtr ) { | ||
| private function processArray( $stackPtr ): void { | ||
|
|
||
| $open_close = Arrays::getOpenClose( $this->phpcsFile, $stackPtr ); | ||
| if ( $open_close === false ) { | ||
|
|
@@ -120,7 +120,7 @@ private function processArray( $stackPtr ) { | |
| * | ||
| * @return void | ||
| */ | ||
| private function processString( $stackPtr ) { | ||
| private function processString( $stackPtr ): void { | ||
|
|
||
| $callbackFunctionName = substr( $this->tokens[ $stackPtr ]['content'], 1, -1 ); | ||
|
|
||
|
|
@@ -147,7 +147,7 @@ private function processString( $stackPtr ) { | |
| * | ||
| * @return void | ||
| */ | ||
| private function processFunction( $stackPtr ) { | ||
| private function processFunction( $stackPtr ): void { | ||
|
|
||
| $wpQueryObjectNamePtr = $this->phpcsFile->findNext( | ||
| [ T_VARIABLE ], | ||
|
|
@@ -182,7 +182,7 @@ private function processFunction( $stackPtr ) { | |
| * | ||
| * @return void | ||
| */ | ||
| private function processClosure( $stackPtr ) { | ||
| private function processClosure( $stackPtr ): void { | ||
|
|
||
| $wpQueryObjectNamePtr = $this->phpcsFile->findNext( | ||
| [ T_VARIABLE ], | ||
|
|
@@ -209,7 +209,7 @@ private function processClosure( $stackPtr ) { | |
| * | ||
| * @return void | ||
| */ | ||
| private function processFunctionBody( $stackPtr, $variableName ) { | ||
| private function processFunctionBody( $stackPtr, $variableName ): void { | ||
|
|
||
| $functionBodyScopeStart = $this->tokens[ $stackPtr ]['scope_opener']; | ||
| $functionBodyScopeEnd = $this->tokens[ $stackPtr ]['scope_closer']; | ||
|
|
@@ -250,7 +250,7 @@ private function processFunctionBody( $stackPtr, $variableName ) { | |
| * | ||
| * @return void | ||
| */ | ||
| private function addPreGetPostsWarning( $stackPtr ) { | ||
| private function addPreGetPostsWarning( $stackPtr ): void { | ||
| $message = 'Main WP_Query is being modified without `$query->is_main_query()` check. Needs manual inspection.'; | ||
| $this->phpcsFile->addWarning( $message, $stackPtr, 'PreGetPosts' ); | ||
| } | ||
|
|
@@ -262,7 +262,7 @@ private function addPreGetPostsWarning( $stackPtr ) { | |
| * | ||
| * @return bool | ||
| */ | ||
| private function isParentConditionalCheckingMainQuery( $stackPtr ) { | ||
| private function isParentConditionalCheckingMainQuery( $stackPtr ): bool { | ||
|
|
||
| if ( array_key_exists( 'conditions', $this->tokens[ $stackPtr ] ) === false | ||
| || is_array( $this->tokens[ $stackPtr ]['conditions'] ) === false | ||
|
|
@@ -312,7 +312,7 @@ private function isParentConditionalCheckingMainQuery( $stackPtr ) { | |
| * | ||
| * @return bool | ||
| */ | ||
| private function isEarlyMainQueryCheck( $stackPtr ) { | ||
| private function isEarlyMainQueryCheck( $stackPtr ): bool { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not something this PR introduces, but I noticed it while checking the add_action( 'pre_get_posts', function( $query ) {
if ( ! $query->is_main_query() ) {
do_log( 'x' );
return;
}
$query->set( 'cat', '-5' );
} );Remove the Tiny nit while we're here, now that it's typed: the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can reproduce that with the snippet, but I think it needs an issue and another PR |
||
|
|
||
| if ( ! $this->isWPQueryMethodCall( $stackPtr, 'is_main_query' ) ) { | ||
| return false; | ||
|
|
@@ -365,11 +365,7 @@ private function isEarlyMainQueryCheck( $stackPtr ) { | |
| true | ||
| ); | ||
|
|
||
| if ( $next ) { | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| return $next !== false; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -380,7 +376,7 @@ private function isEarlyMainQueryCheck( $stackPtr ) { | |
| * | ||
| * @return bool | ||
| */ | ||
| private function isWPQueryMethodCall( $stackPtr, $method = null ) { | ||
| private function isWPQueryMethodCall( $stackPtr, $method = null ): bool { | ||
| $next = $this->phpcsFile->findNext( | ||
| Tokens::$emptyTokens, | ||
| $stackPtr + 1, | ||
|
|
@@ -417,7 +413,7 @@ private function isWPQueryMethodCall( $stackPtr, $method = null ) { | |
| * | ||
| * @return bool | ||
| */ | ||
| private function isPartOfIfConditional( $stackPtr ) { | ||
| private function isPartOfIfConditional( $stackPtr ): bool { | ||
|
|
||
| if ( array_key_exists( 'nested_parenthesis', $this->tokens[ $stackPtr ] ) === true | ||
| && is_array( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) === true | ||
|
|
@@ -448,7 +444,7 @@ private function isPartOfIfConditional( $stackPtr ) { | |
| * | ||
| * @return bool | ||
| */ | ||
| private function isInsideIfConditonal( $stackPtr ) { | ||
| private function isInsideIfConditonal( $stackPtr ): bool { | ||
|
|
||
| if ( array_key_exists( 'conditions', $this->tokens[ $stackPtr ] ) === true | ||
| && is_array( $this->tokens[ $stackPtr ]['conditions'] ) === true | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional nit: with
: booldeclared, thereturn ! ( $this->tokens[ $previous ]['code'] === T_FUNCTION );at the end of this method might read a little more directly asreturn $this->tokens[ $previous ]['code'] !== T_FUNCTION;. Entirely up to you.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both done in b7d2927