Documentation

Squiz_Sniffs_Operators_ComparisonOperatorUsageSniff
in package
implements PHP_CodeSniffer_Sniff

A Sniff to enforce the use of IDENTICAL type operators rather than EQUAL operators.

The use of === true is enforced over implicit true statements, for example:

if ($a) { ... }

should be:

if ($a === true) { ... }

It also enforces the use of === false over ! operators.

Tags
category

PHP

author

Greg Sherwood gsherwood@squiz.net

author

Marc McIntyre mmcintyre@squiz.net

copyright

2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)

license

https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence

version

Release: @package_version@

link
http://pear.php.net/package/PHP_CodeSniffer

Interfaces, Classes and Traits

PHP_CodeSniffer_Sniff
Represents a PHP_CodeSniffer sniff for sniffing coding standards.

Table of Contents

$supportedTokenizers  : array<string|int, mixed>
A list of tokenizers this sniff supports.
$_invalidOps  : mixed
A list of invalid operators with their alternatives.
$_validOps  : array<string|int, mixed>
A list of valid comparison operators.
process()  : void
Process the tokens that this sniff is listening for.
register()  : array<string|int, mixed>
Registers the token types that this sniff wishes to listen to.

Properties

$supportedTokenizers

A list of tokenizers this sniff supports.

public array<string|int, mixed> $supportedTokenizers = array('PHP', 'JS')

$_invalidOps

A list of invalid operators with their alternatives.

private static mixed $_invalidOps = array('PHP' => array(T_IS_EQUAL => '===', T_IS_NOT_EQUAL => '!==', T_BOOLEAN_NOT => '=== FALSE'), 'JS' => array(T_IS_EQUAL => '===', T_IS_NOT_EQUAL => '!=='))

$_validOps

A list of valid comparison operators.

private static array<string|int, mixed> $_validOps = array(T_IS_IDENTICAL, T_IS_NOT_IDENTICAL, T_LESS_THAN, T_GREATER_THAN, T_IS_GREATER_OR_EQUAL, T_IS_SMALLER_OR_EQUAL, T_INSTANCEOF)

Methods

process()

Process the tokens that this sniff is listening for.

public process(PHP_CodeSniffer_File $phpcsFile, int $stackPtr) : void
Parameters
$phpcsFile : PHP_CodeSniffer_File

The file where the token was found.

$stackPtr : int

The position in the stack where the token was found.

Return values
void

register()

Registers the token types that this sniff wishes to listen to.

public register() : array<string|int, mixed>
Return values
array<string|int, mixed>

Search results