-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LowerCamelFunctionsNameSniff: Ignore hook methods
For function names that have an underscore, check if the class implements a hook interface associated with that method, using the logic that a hook `on(Something)` comes from a hook interface named `(Something)Hook` Bug: T273482 Change-Id: I4c5d7fe7a533a2de885a5d9e6d3fb2a3470ea924
- Loading branch information
1 parent
b2eb92e
commit 8b4eb65
Showing
4 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
MediaWiki/Tests/files/NamingConventions/lower_camel_functions_name_hooks.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
use MediaWiki\Hook\RecentChange_saveHook; | ||
|
||
class HookHandler implements | ||
RecentChange_saveHook, | ||
\MediaWiki\SpecialPage\Hook\SpecialPage_initListHook | ||
{ | ||
/** | ||
* This method name comes from the hook and cannot be changed, phpcs should not complain | ||
* (the interface for this hook is imported with a `use` statement, and the `implements` | ||
* only has the final interface name | ||
* | ||
* @param RecentChange $recentChange | ||
* @return bool|void True or no return value to continue or false to abort | ||
*/ | ||
public function onRecentChange_save( $recentChange ) { | ||
return false; | ||
} | ||
|
||
/** | ||
* This method name comes from the hook and cannot be changed, phpcs should not complain | ||
* (the interface for this hook is not imported with a `use` statement, and the `implements` | ||
* has the fully qualified name | ||
* | ||
* @param array &$list List of core special pages | ||
* @return bool|void True or no return value to continue or false to abort | ||
*/ | ||
public function onSpecialPage_initList( &$list ) { | ||
return false; | ||
} | ||
|
||
/** | ||
* This method is not inherited from an interface, and can be changed, phpcs should complain, | ||
* even though it looks like a hook handler | ||
* | ||
* @param SpecialUpload $upload | ||
* @return bool|void True or no return value to continue or false to abort | ||
*/ | ||
public function onUploadForm_initial( $upload ) { | ||
return false; | ||
} | ||
|
||
/** | ||
* This method is not inherited from an interface and does not look like a hook handler, | ||
* phpcs should complain | ||
* | ||
* @return bool | ||
*/ | ||
public function getThe_thing() { | ||
return false; | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
MediaWiki/Tests/files/NamingConventions/lower_camel_functions_name_hooks.php.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
40 | ERROR | Method name "onUploadForm_initial" should use lower camel case. | ||
| | (MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName) | ||
50 | ERROR | Method name "getThe_thing" should use lower camel case. | ||
| | (MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName) |