All Projects → Moxio → php-codesniffer-sniffs

Moxio / php-codesniffer-sniffs

Licence: MIT license
Custom sniffs for PHP_CodeSniffer

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to php-codesniffer-sniffs

phpcs-psr4-sniff
[READ-ONLY] PHP_CodeSniffer sniff that checks class name matches PSR-4 project structure.
Stars: ✭ 23 (+43.75%)
Mutual labels:  static-analysis, coding-standards, php-codesniffer
wptide
🌊 Tide is a series of automated tests run against every WordPress.org theme and plugin
Stars: ✭ 77 (+381.25%)
Mutual labels:  coding-standards, php-codesniffer
sniff
Simpler PHP code sniffer built on top of PHP-CS-Fixer.
Stars: ✭ 14 (-12.5%)
Mutual labels:  coding-standards, php-codesniffer
coding-standard
Consistence - Coding Standard - PHP Code Sniffer rules
Stars: ✭ 73 (+356.25%)
Mutual labels:  coding-standards, php-codesniffer
OpenStaticAnalyzer
OpenStaticAnalyzer is a source code analyzer tool, which can perform deep static analysis of the source code of complex systems.
Stars: ✭ 19 (+18.75%)
Mutual labels:  static-analysis, coding-standards
Phpcs Calisthenics Rules
Object Calisthenics rules for PHP_CodeSniffer
Stars: ✭ 605 (+3681.25%)
Mutual labels:  static-analysis, php-codesniffer
Codor
Custom PHPCS sniffs to find Code Smells
Stars: ✭ 40 (+150%)
Mutual labels:  coding-standards, php-codesniffer
codeclimate-phpcodesniffer
Code Climate Engine for PHP Code Sniffer
Stars: ✭ 27 (+68.75%)
Mutual labels:  static-analysis, php-codesniffer
Phpqa
Docker image that provides static analysis tools for PHP
Stars: ✭ 853 (+5231.25%)
Mutual labels:  static-analysis, php-codesniffer
Php codesniffer
PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.
Stars: ✭ 9,004 (+56175%)
Mutual labels:  static-analysis, coding-standards
Vehicle-Security-Toolkit
汽车/安卓/固件/代码安全测试工具集
Stars: ✭ 367 (+2193.75%)
Mutual labels:  static-analysis
qulice
Quality Police for Java projects: aggregator of Checkstyle, PMD, and SpotBugs
Stars: ✭ 286 (+1687.5%)
Mutual labels:  static-analysis
grunt-wp-css
Format style sheets according to the WordPress CSS coding standards.
Stars: ✭ 36 (+125%)
Mutual labels:  coding-standards
ramllint
RAML Linter
Stars: ✭ 18 (+12.5%)
Mutual labels:  static-analysis
phpcs-gitlab
Gitlab Report for PHP_CodeSniffer (display the violations in the Gitlab CI/CD Code Quality Report)
Stars: ✭ 29 (+81.25%)
Mutual labels:  php-codesniffer
eslint-config
MOXY eslint configuration to be used across several JavaScript projects
Stars: ✭ 14 (-12.5%)
Mutual labels:  coding-standards
localhost-sonarqube
Analysing source code locally with SonarQube in a Docker environment.
Stars: ✭ 17 (+6.25%)
Mutual labels:  static-analysis
klever
Read-only mirror of the Klever Git repository
Stars: ✭ 18 (+12.5%)
Mutual labels:  static-analysis
subpy
Python subsets
Stars: ✭ 41 (+156.25%)
Mutual labels:  static-analysis
phpstan-wordpress
WordPress extensions for PHPStan ⛏️
Stars: ✭ 182 (+1037.5%)
Mutual labels:  static-analysis

Continuous Integration Latest Stable Version

Moxio PHP_CodeSniffer sniffs

This is a collection of our custom PHP_Codesniffer (3.x) sniffs for detecting potential bugs and unexpected behavior in PHP code. It may be used as a ruleset on its own, but it is mainly intended as a set of separate sniffs that can be integrated into other standards.

We described the motivation behind some of these sniffs on our blog.

Installation and usage

Install as a development dependency using composer:

$ composer require --dev moxio/php-codesniffer-sniffs

Check your files against this set of sniffs:

$ ./vendor/bin/phpcs --standard=vendor/moxio/php-codesniffer-sniffs/MoxioSniffs path/to/your/files

Description of sniffs

More sniffs will be added soon.

MoxioSniffs.PHP.DisallowBareContinueInSwitch: Disallows the continue statement without a numeric argument when used directly within a switch-case. This prevents silent bugs caused by PHP considering switch to be a looping structure.

MoxioSniffs.PHP.DisallowImplicitLooseComparison: Disallows implicit non-strict comparisons by functions like in_array and array_search. Requires that the $strict-parameter to these functions is explicitly set. This prevents hidden bugs due to counter-intuitive behavior of non-strict comparison.

MoxioSniffs.PHP.DisallowImplicitLooseBase64Decode: Disallows implicit non-strict usage of the base64_decode function. Requires that the $strict-parameter to this function is explicitly set.

MoxioSniffs.PHP.DisallowUniqidWithoutMoreEntropy: Disallows calls to uniqid() without $more_entropy = true. When $more_entropy is false (which is the default), uniqid() calls usleep() to avoid collisions, which can be a substantial performance hit. Always calling uniqid() with $more_entropy = true avoids these problems.

MoxioSniffs.PHP.DisallowArrayCombinersWithSingleArray: Disallows calls to functions that combine two or more arrays with only a single array given as an argument. This applies to functions like array_merge(_recursive), array_replace(_recursive) and all variants of array_diff and array_intersect. Such a call does not make sense, and is most likely a result of a misplaced comma or parenthesis. To re-index a single array, just use array_values.

MoxioSniffs.PHP.DisallowImplicitMicrotimeAsString: Disallows calls to microtime() without the $get_as_float argument being explicitly set. By default, microtime has a string as its return value ("msec sec"), which is unexpected and cannot be naively cast to float, making it error-prone. It is still possible to set this argument to false, but in that case you have probably thought about this.

MoxioSniffs.PHP.DisallowImplicitIteratorToArrayWithUseKeys: Disallows calls to iterator_to_array() without the $use_keys argument being explicitly set. By default, iterator_to_array uses the keys provided by the iterator. This behavior is often desired for associative arrays, but can cause unexpected results for 'list-like' arrays. Explicitly requiring the parameter to be set ensures that the developer has to think about which behavior is desired for the situation at hand.

MoxioSniffs.PHP.DisallowDateTime: Disallows usage of \DateTime and promotes the use of \DateTimeImmutable instead. The former being mutable can lead to some subtle but nasty bugs. See this post for more background on why you would want to discourage using \DateTime.

MoxioSniffs.PHP.DisallowMbDetectEncoding: Disallows usage of mb_detect_encoding. This function has a misleading name that implies it can actually detect the encoding of a string, a problem which is generally impossible. Rather it checks a list of encodings until it finds one that could be the right one (i.e. the string is a valid byte sequence according to that encoding). Using mb_check_encoding (possibly in a loop) instead makes this much more explicit. See this talk for more background information on this topic.

MoxioSniffs.PHP.DisallowUtf8EncodeDecode: Disallows calls to utf8_encode() and utf8_decode(). These functions can be considered misleading because they only convert to/from ISO-8859-1, and do not 'magically' detect the source/target encoding. Using iconv() or mb_convert_encoding() instead makes both character encodings that play a role in the conversion explicit.

Running tests

After installing dependencies (including development dependencies) using Composer, run

$ ./vendor/bin/phpunit

from the project root dir.

Versioning

This project adheres to Semantic Versioning.

Please note that, from the perspective of this library as a pick-and-match collection of sniffs (and not a complete coding standard), the addition of new sniffs will not be considered a breaking change and thus does not cause an increase in the major version number.

License

These sniffs are released under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].