PHP_CodeSniffer
[ class tree: PHP_CodeSniffer ] [ index: PHP_CodeSniffer ] [ all elements ]

Class: PHP_CodeSniffer

Source Location: /PHP_CodeSniffer-0.7.0/CodeSniffer.php

Class Overview


PHP_CodeSniffer tokenises PHP code and detects violations of a defined set of coding standards.


Author(s):

Version:

  • Release: 0.7.0

Copyright:

  • 2006 Squiz Pty Ltd (ABN 77 084 670 600)

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 48]
PHP_CodeSniffer tokenises PHP code and detects violations of a defined set of coding standards.

Standards are specified by classes that implement the PHP_CodeSniffer_Sniff interface. A sniff registers what token types it wishes to listen for, then PHP_CodeSniffer encounters that token, the sniff is invoked and passed information about where the token was found in the stack, and the token stack itself.

Sniff files and their containing class must be prefixed with Sniff, and have an extension of .php.

Multiple PHP_CodeSniffer operations can be performed by re-calling the process function with different parameters.



[ Top ]


Class Variables

$allowedTypes = array(
                                   'array',
                                   'boolean',
                                   'float',
                                   'integer',
                                   'mixed',
                                   'object',
                                   'string',
                                  )

[line 94]

An array of variable types for param/var we will check.
  • Access: public

Type:   array(string)


[ Top ]



Method Detail

__construct (Constructor)   [line 114]

PHP_CodeSniffer __construct( [int $verbosity = 0])

Constructs a PHP_CodeSniffer object.

Parameters:

int   $verbosity   —  The verbosity level. 1: Print progress information. 2: Print developer debug information.

[ Top ]

generateDocs   [line 701]

void generateDocs( string $standard, [array $sniffs = array()], [string $generator = 'text'])

Generates documentation for a coding standard.
  • Access: public

Parameters:

string   $standard   —  The standard to generate docs for
array   $sniffs   —  A list of sniffs to limit the docs to.
string   $generator   —  The name of the generator class to use.

[ Top ]

getFiles   [line 718]

array(PHP_CodeSniffer_File) getFiles( )

Returns the PHP_CodeSniffer file objects.
  • Access: public

[ Top ]

getInstalledStandards   [line 1071]

array getInstalledStandards( [boolean $includeGeneric = false])

Get a list of all coding standards installed.

Coding standards are directories located in the CodeSniffer/Standards directory. Valid coding standards include a Sniffs subdirectory.


Parameters:

boolean   $includeGeneric   —  If true, the special "Generic" coding standard will be included if installed.

[ Top ]

getSniffFiles   [line 268]

array getSniffFiles( string $dir, [string $standard = null])

Return a list of sniffs that a coding standard has defined.

Sniffs are found by recursing the standard directory and also by asking the standard for included sniffs.

  • Throws: PHP_CodeSniffer_Exception If an included or excluded sniff does not exist.
  • Access: public

Parameters:

string   $dir   —  The directory where to look for the files.
string   $standard   —  The name of the coding standard. If NULL, no included sniffs will be checked for.

[ Top ]

isCamelCaps   [line 919]

boolean isCamelCaps( string $string, [boolean $classFormat = false], [boolean $public = true], [boolean $strict = true])

Returns true if the specified string is in the camel caps format.
  • Access: public

Parameters:

string   $string   —  The string the verify.
boolean   $classFormat   —  If true, check to see if the string is in the class format. Class format strings must start with a capital letter and contain no underscores.
boolean   $public   —  If true, the first character in the string must be an a-z character. If false, the character must be an underscore. This argument is only applicable if $classFormat is false.
boolean   $strict   —  If true, the string must not have two captial letters next to each other. If false, a relaxed camel caps policy is used to allow for acronyms.

[ Top ]

isInstalledStandard   [line 1111]

boolean isInstalledStandard( string $standard)

Determine if a standard is installed.

Coding standards are directories located in the CodeSniffer/Standards directory. Valid coding standards include a Sniffs subdirectory.


Parameters:

string   $standard   —  The name of the coding standard.

[ Top ]

isUnderscoreName   [line 974]

boolean isUnderscoreName( string $string)

Returns true if the specified string is in the underscore caps format.
  • Access: public

Parameters:

string   $string   —  The string to verify.

[ Top ]

printErrorReport   [line 476]

int printErrorReport( [boolean $showWarnings = true])

Prints all errors and warnings for each file processed.

Errors and warnings are displayed together, grouped by file.

  • Return: The number of error and warning messages shown.
  • Access: public

Parameters:

boolean   $showWarnings   —  Show warnings as well as errors.

[ Top ]

printErrorReportSummary   [line 614]

int printErrorReportSummary( [boolean $showWarnings = true])

Prints a summary of errors and warnings for each file processed.

If verbose output is enabled, results are shown for all files, even if they have no errors or warnings. If verbose output is disabled, we only show files that have at least one warning or error.

  • Return: The number of error and warning messages shown.
  • Access: public

Parameters:

boolean   $showWarnings   —  Show warnings as well as errors.

[ Top ]

process   [line 150]

void process( string|array $files, string $standard, [array $sniffs = array()], [boolean $local = false])

Processes the files/directories that PHP_CodeSniffer was constructed with.
  • Throws: PHP_CodeSniffer_Exception If files or standard are invalid.
  • Access: public

Parameters:

string|array   $files   —  The files and directories to process. For directories, each sub directory will also be traversed for source files.
string   $standard   —  The set of code sniffs we are testing against.
array   $sniffs   —  The sniff names to restrict the allowed listeners to.
boolean   $local   —  If true, don't recurse into directories.

[ Top ]

resolveSimpleToken   [line 811]

array resolveSimpleToken( string $token)

Converts simple tokens into a format that conforms to complex tokens produced by token_get_all().

Simple tokens are tokens that are not in array form when produced from token_get_all().

  • Return: The new token in array format.
  • Access: public

Parameters:

string   $token   —  The simple token to convert.

[ Top ]

resolveTstringToken   [line 768]

array resolveTstringToken( array $token)

Converts T_STRING tokens into more usable token names.

The token should be produced using the token_get_all() function. Currently, not all T_STRING tokens are converted.

  • Return: The new token.
  • Access: public

Parameters:

string|array   $token   —  The T_STRING token to convert as constructed by token_get_all().

[ Top ]

setAllowedFileExtensions   [line 128]

void setAllowedFileExtensions( array $extensions)

Sets an array of file extensions that we will allow checking of.
  • Access: public

Parameters:

array   $extensions   —  An array of file extensions.

[ Top ]

standardiseToken   [line 736]

array standardiseToken( string|array $token)

Takes a token produced from
and produces a more uniform token.

Note that this method also resolves T_STRING tokens into more descrete types, therefore there is no need to call resolveTstringToken()

  • Return: The new token.
  • Access: public

Parameters:

string|array   $token   —  The token to convert.

[ Top ]

suggestType   [line 1006]

string suggestType( string $varType)

Returns a valid variable type for param/var tag.

If type is not one of the standard type, it must be a custom type. Returns the correct type name suggestion if type name is invalid.

  • Access: public

Parameters:

string   $varType   —  The variable type to process.

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:06:34 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.