MessageHelper
in package
Helper functions for creating PHPCS error/warning messages.
Tags
Table of Contents
Methods
- addFixableMessage() : bool
- Add a PHPCS message to the output stack as either a fixable warning or a fixable error.
- addMessage() : bool
- Add a PHPCS message to the output stack as either a warning or an error.
- showEscapeChars() : string
- Make the whitespace escape codes used in an arbitrary text string visible.
- stringToErrorcode() : string
- Convert an arbitrary text string to an alphanumeric string with underscores.
Methods
addFixableMessage()
Add a PHPCS message to the output stack as either a fixable warning or a fixable error.
public
static addFixableMessage(File $phpcsFile, string $message, int $stackPtr[, bool $isError = true ][, string $code = 'Found' ][, array<string|int, scalar> $data = [] ][, int $severity = 0 ]) : bool
Parameters
- $phpcsFile : File
-
The file where this token was found.
- $message : string
-
The message.
- $stackPtr : int
-
The position of the token the message relates to.
- $isError : bool = true
-
Whether to report the message as an 'error' or 'warning'. Defaults to true (error).
- $code : string = 'Found'
-
The error code for the message. Defaults to 'Found'.
- $data : array<string|int, scalar> = []
-
Optional input for the data replacements.
- $severity : int = 0
-
Optional. Severity level. Defaults to 0 which will translate to the PHPCS default severity level.
Tags
Return values
booladdMessage()
Add a PHPCS message to the output stack as either a warning or an error.
public
static addMessage(File $phpcsFile, string $message, int $stackPtr[, bool $isError = true ][, string $code = 'Found' ][, array<string|int, scalar> $data = [] ][, int $severity = 0 ]) : bool
Parameters
- $phpcsFile : File
-
The file where this token was found.
- $message : string
-
The message.
- $stackPtr : int
-
The position of the token the message relates to.
- $isError : bool = true
-
Whether to report the message as an 'error' or 'warning'. Defaults to true (error).
- $code : string = 'Found'
-
The error code for the message. Defaults to 'Found'.
- $data : array<string|int, scalar> = []
-
Optional input for the data replacements.
- $severity : int = 0
-
Optional. Severity level. Defaults to 0 which will translate to the PHPCS default severity level.
Tags
Return values
boolshowEscapeChars()
Make the whitespace escape codes used in an arbitrary text string visible.
public
static showEscapeChars(string $text) : string
At times, it is useful to show a code snippet in an error message. If such a code snippet contains new lines and/or tab or space characters, those would be displayed as-is in the command-line report, often breaking the layout of the report or making the report harder to read.
This method will convert these characters to their escape codes, making them visible in the display string without impacting the report layout.
Parameters
- $text : string
-
Arbitrary text string.
Tags
Return values
stringstringToErrorcode()
Convert an arbitrary text string to an alphanumeric string with underscores.
public
static stringToErrorcode(string $text[, bool $strtolower = false ]) : string
Pre-empt issues in XML and PHP when arbitrary strings are being used as error codes.
Parameters
- $text : string
-
Arbitrary text string intended to be used in an error code.
- $strtolower : bool = false
-
Whether or not to convert the text string to lowercase.