-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #281 from PHPCSStandards/feature/164-handle-sniff-…
…deprecation-natively ✨ Native handling of sniff deprecations
- Loading branch information
Showing
25 changed files
with
1,274 additions
and
0 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* Marks a sniff as deprecated. | ||
* | ||
* Implementing this interface allows for marking a sniff as deprecated and | ||
* displaying information about the deprecation to the end-user. | ||
* | ||
* A sniff will still need to implement the `PHP_CodeSniffer\Sniffs\Sniff` interface | ||
* as well, or extend an abstract sniff which does, to be recognized as a valid sniff. | ||
* | ||
* @author Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl> | ||
* @copyright 2024 PHPCSStandards Contributors | ||
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence | ||
*/ | ||
|
||
namespace PHP_CodeSniffer\Sniffs; | ||
|
||
interface DeprecatedSniff | ||
{ | ||
|
||
|
||
/** | ||
* Provide the version number in which the sniff was deprecated. | ||
* | ||
* Recommended format for PHPCS native sniffs: "v3.3.0". | ||
* Recommended format for external sniffs: "StandardName v3.3.0". | ||
* | ||
* @return string | ||
*/ | ||
public function getDeprecationVersion(); | ||
|
||
|
||
/** | ||
* Provide the version number in which the sniff will be removed. | ||
* | ||
* Recommended format for PHPCS native sniffs: "v3.3.0". | ||
* Recommended format for external sniffs: "StandardName v3.3.0". | ||
* | ||
* If the removal version is not yet known, it is recommended to set | ||
* this to: "a future version". | ||
* | ||
* @return string | ||
*/ | ||
public function getRemovalVersion(); | ||
|
||
|
||
/** | ||
* Optionally provide an arbitrary custom message to display with the deprecation. | ||
* | ||
* Typically intended to allow for displaying information about what to | ||
* replace the deprecated sniff with. | ||
* Example: "Use the Stnd.Cat.SniffName sniff instead." | ||
* Multi-line messages (containing new line characters) are supported. | ||
* | ||
* An empty string can be returned if there is no replacement/no need | ||
* for a custom message. | ||
* | ||
* @return string | ||
*/ | ||
public function getDeprecationMessage(); | ||
|
||
|
||
}//end interface |
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
41 changes: 41 additions & 0 deletions
41
tests/Core/Ruleset/Fixtures/Sniffs/Deprecated/WithLongReplacementSniff.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,41 @@ | ||
<?php | ||
/** | ||
* Test fixture. | ||
* | ||
* @see \PHP_CodeSniffer\Tests\Core\Ruleset\SniffDeprecationTest | ||
*/ | ||
|
||
namespace Fixtures\Sniffs\Deprecated; | ||
|
||
use PHP_CodeSniffer\Files\File; | ||
use PHP_CodeSniffer\Sniffs\DeprecatedSniff; | ||
use PHP_CodeSniffer\Sniffs\Sniff; | ||
|
||
class WithLongReplacementSniff implements Sniff,DeprecatedSniff | ||
{ | ||
|
||
public function getDeprecationVersion() | ||
{ | ||
return 'v3.8.0'; | ||
} | ||
|
||
public function getRemovalVersion() | ||
{ | ||
return 'v4.0.0'; | ||
} | ||
|
||
public function getDeprecationMessage() | ||
{ | ||
return 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce vel vestibulum nunc. Sed luctus dolor tortor, eu euismod purus pretium sed. Fusce egestas congue massa semper cursus. Donec quis pretium tellus. In lacinia, augue ut ornare porttitor, diam nunc faucibus purus, et accumsan eros sapien at sem. Sed pulvinar aliquam malesuada. Aliquam erat volutpat. Mauris gravida rutrum lectus at egestas. Fusce tempus elit in tincidunt dictum. Suspendisse dictum egestas sapien, eget ullamcorper metus elementum semper. Vestibulum sem justo, consectetur ac tincidunt et, finibus eget libero.'; | ||
} | ||
|
||
public function register() | ||
{ | ||
return [T_WHITESPACE]; | ||
} | ||
|
||
public function process(File $phpcsFile, $stackPtr) | ||
{ | ||
// Do something. | ||
} | ||
} |
Oops, something went wrong.