SeparateFunctionsFromOOSniff
in package
implements
Sniff
FinalYes
A file should either declare (global/namespaced) functions or declare OO structures, but not both.
Nested function declarations, i.e. functions declared within a function/method will be disregarded for the purposes of this sniff. The same goes for anonymous classes, closures and arrow functions.
Notes:
- This sniff has no opinion on side effects. If you want to sniff for those, use the PHPCS
native
PSR1.Files.SideEffectssniff. - This sniff has no opinion on multiple OO structures being declared in one file.
If you want to sniff for that, use the PHPCS native
Generic.Files.OneObjectStructurePerFilesniff.
Tags
Table of Contents
Interfaces
Constants
- METRIC_NAME = 'Functions or OO declarations ?'
- Name of the metric.
Properties
- $search : array<string|int, int|string>
- Tokens this sniff searches for.
Methods
- process() : int|void
- Processes this test, when one of its tokens is encountered.
- register() : array<string|int, int|string>
- Returns an array of tokens this test wants to listen for.
Constants
METRIC_NAME
Name of the metric.
public
string
METRIC_NAME
= 'Functions or OO declarations ?'
Tags
Properties
$search
Tokens this sniff searches for.
private
array<string|int, int|string>
$search
= [
// Some tokens to help skip over structures we're not interested in.
\T_START_HEREDOC => \T_START_HEREDOC,
\T_START_NOWDOC => \T_START_NOWDOC,
]
Enhanced from within the register() methods.
Tags
Methods
process()
Processes this test, when one of its tokens is encountered.
public
process(File $phpcsFile, int $stackPtr) : int|void
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The position of the current token in the stack passed in $tokens.
Tags
Return values
int|void —Integer stack pointer to skip forward or void to continue normal file processing.
register()
Returns an array of tokens this test wants to listen for.
public
register() : array<string|int, int|string>