Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7415573
EmptyStatementSniff.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
EmptyStatementSniff.php
View Options
<?php
/**
* This sniff class detected empty statement.
*
* This sniff implements the common algorithm for empty statement body detection.
* A body is considered as empty if it is completely empty or it only contains
* whitespace characters and/or comments.
*
* <code>
* stmt {
* // foo
* }
* stmt (conditions) {
* // foo
* }
* </code>
*
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2007-2014 Manuel Pichler. All rights reserved.
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/
namespace
PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis
;
use
PHP_CodeSniffer\Files\File
;
use
PHP_CodeSniffer\Sniffs\Sniff
;
use
PHP_CodeSniffer\Util\Tokens
;
class
EmptyStatementSniff
implements
Sniff
{
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return array<int|string>
*/
public
function
register
()
{
return
[
T_TRY
,
T_CATCH
,
T_FINALLY
,
T_DO
,
T_ELSE
,
T_ELSEIF
,
T_FOR
,
T_FOREACH
,
T_IF
,
T_SWITCH
,
T_WHILE
,
T_MATCH
,
];
}
//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public
function
process
(
File
$phpcsFile
,
$stackPtr
)
{
$tokens
=
$phpcsFile
->
getTokens
();
$token
=
$tokens
[
$stackPtr
];
// Skip statements without a body.
if
(
isset
(
$token
[
'scope_opener'
])
===
false
)
{
return
;
}
$next
=
$phpcsFile
->
findNext
(
Tokens
::
$emptyTokens
,
(
$token
[
'scope_opener'
]
+
1
),
(
$token
[
'scope_closer'
]
-
1
),
true
);
if
(
$next
!==
false
)
{
return
;
}
// Get token identifier.
$name
=
strtoupper
(
$token
[
'content'
]);
$error
=
'Empty %s statement detected'
;
$phpcsFile
->
addError
(
$error
,
$stackPtr
,
'Detected'
.
ucfirst
(
strtolower
(
$name
)),
[
$name
]);
}
//end process()
}
//end class
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 02:15 (1 d, 12 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
74/d8/d151007df785d0b55667a45b2486
Default Alt Text
EmptyStatementSniff.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment