danbettles/codesniffer-standard
最新稳定版本:v3.0.0
Composer 安装命令:
composer require danbettles/codesniffer-standard
包简介
A PHP_CodeSniffer standard that mainly looks for abandoned debugging code
README 文档
README
Important
This version of my PHP_CodeSniffer Standard is for PHP_CodeSniffer 4 and PHP 8.3+. Previous major versions target older incarnations of PHP_CodeSniffer and PHP.
Tip
You may like to read about how to unit-test a custom PHPCS Standard without having to 'install' it
The Sniffs
Errors
- PHP debugging functions (
print_randvar_dump) are forbidden because I never use them for anything other than debugging.
Warnings
- PHP output functions (
printandecho) are considered suspect because I rarely—if ever—use them for anything other than debugging in object-oriented code, and since I tend to use short-echo tags (<?= ?>) in output templates, I don't expect to see them elsewhere either. - PHP script termination functions (
exitanddie) are considered suspect because they needn't be used in well-structured code; I use them only when debugging. I consider it bad-form to use these functions in a framework because they will likely prevent an application shutting-down cleanly, which, for one thing, can make it difficult to find out why output filters—or the like—are not being applied. JavaScript'salertfunction (window.alert()) is considered suspect because it's probably used more for debugging than anything else.- Comments appearing to contain debugging code will be the subject of warnings. Debugging code should never be committed, even if it's commented. At the very least, commented debugging code is garbage, unwanted noise, and there's no sense in making your code more difficult to follow by leaving it lying around.
- One way or another,
TODOandFIXMEtags signal potential problems on the road ahead.
Installation
Install using Composer, thus:
composer --dev require danbettles/codesniffer-standard
Usage
You can reference the Standard on the command-line with:
--standard=path/to/vendor/danbettles/codesniffer-standard/src/DanBettles
Alternatively, add the following Rule Element to your XML config file.
<rule ref="path/to/vendor/danbettles/codesniffer-standard/src/DanBettles"> </rule>
The Unit Tests
I had some difficulty upgrading the unit-tests for PHP_CodeSniffer 3 and I still didn't like that you have to 'install' your custom Standard as part of the usual PHPCS approach. After some investigation, I tried Payton Swick's solution, which worked out well—thank you, Payton.
Payton Swick's solution enables you to test your custom Standard in isolation, within the project. I developed his idea a little further, creating a sensibly opinionated test-case base-class that makes it straightforward to test your sniffs: straightforward if you follow usual PHPUnit conventions, and straightforward because it involves using PHPUnit in a more natural way.
统计信息
- 总下载量: 522
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 17
- 推荐数: 0
其他信息
- 授权协议: ISC
- 更新时间: 2014-12-31