Documentation

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.SideEffects sniff.
  • 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.OneObjectStructurePerFile sniff.
Tags
since
1.0.0

Table of Contents

Interfaces

Sniff

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

Properties

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
since
1.0.0

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
since
1.0.0
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>
Tags
since
1.0.0
Return values
array<string|int, int|string>

        
On this page

Search results