Documentation

Common
in package

Table of Contents

Constants

ALLOWED_TYPES  = ['array' => 'array', 'boolean' => 'boolean', 'float' => 'float', 'integer' => 'integer', 'mixed' => 'mixed', 'object' => 'object', 'string' => 'string', 'resource' => 'resource', 'callable' => 'callable']
An array of variable types for param/var we will check.

Properties

$allowedTypes  : array<string, string>
An array of variable types for param/var we will check.

Methods

cleanSniffClass()  : string
Removes project-specific information from a sniff class name.
detectLineEndings()  : string
Detects the EOL character being used in a string.
escapeshellcmd()  : string
Escape a path to a system command.
getSniffCode()  : string
Given a sniff class name, returns the code for the sniff.
isCamelCaps()  : bool
Returns true if the specified text string is in the camel caps format.
isPharFile()  : bool
Return TRUE if the path is a PHAR file.
isReadable()  : bool
Checks if a file is readable.
isStdinATTY()  : bool
Check if STDIN is a TTY.
isUnderscoreName()  : bool
Returns true if the specified text string is in the underscore caps format.
prepareForOutput()  : string
Prepares token content for output to screen.
realpath()  : string|false
CodeSniffer alternative for realpath.
stripBasepath()  : string
Removes a base path from the front of a file path.
stripColors()  : string
Strip colors from a text for output to screen.
suggestType()  : string
Returns a valid variable type for param/var tags.

Constants

ALLOWED_TYPES

An array of variable types for param/var we will check.

public array<string, string> ALLOWED_TYPES = ['array' => 'array', 'boolean' => 'boolean', 'float' => 'float', 'integer' => 'integer', 'mixed' => 'mixed', 'object' => 'object', 'string' => 'string', 'resource' => 'resource', 'callable' => 'callable']

Properties

$allowedTypes

An array of variable types for param/var we will check.

Use the Common::ALLOWED_TYPES constant instead.

public static array<string, string> $allowedTypes = self::ALLOWED_TYPES

Methods

cleanSniffClass()

Removes project-specific information from a sniff class name.

public static cleanSniffClass(string $sniffClass) : string
Parameters
$sniffClass : string

The fully qualified sniff class name.

Return values
string

detectLineEndings()

Detects the EOL character being used in a string.

public static detectLineEndings(string $contents) : string
Parameters
$contents : string

The contents to check.

Return values
string

escapeshellcmd()

Escape a path to a system command.

public static escapeshellcmd(string $cmd) : string
Parameters
$cmd : string

The path to the system command.

Return values
string

getSniffCode()

Given a sniff class name, returns the code for the sniff.

public static getSniffCode(string $sniffClass) : string
Parameters
$sniffClass : string

The fully qualified sniff class name.

Tags
throws
InvalidArgumentException

When $sniffClass is not a non-empty string.

throws
InvalidArgumentException

When $sniffClass is not a valid FQN for a sniff(test) class.

Return values
string

isCamelCaps()

Returns true if the specified text string is in the camel caps format.

public static isCamelCaps(string $name[, bool $classFormat = false ][, bool $visibilityPublic = true ][, bool $strict = true ]) : bool
Parameters
$name : string

The string to verify.

$classFormat : bool = false

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.

$visibilityPublic : bool = true

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.

$strict : bool = true

If true, the string must not have two capital letters next to each other. If false, a relaxed camel caps policy is used to allow for acronyms.

Return values
bool

isPharFile()

Return TRUE if the path is a PHAR file.

public static isPharFile(string $path) : bool
Parameters
$path : string

The path to use.

Return values
bool

isReadable()

Checks if a file is readable.

public static isReadable(string $path) : bool

Addresses PHP bug related to reading files from network drives on Windows. e.g. when using WSL2.

Parameters
$path : string

The path to the file.

Return values
bool

isStdinATTY()

Check if STDIN is a TTY.

public static isStdinATTY() : bool
Return values
bool

isUnderscoreName()

Returns true if the specified text string is in the underscore caps format.

public static isUnderscoreName(string $name) : bool
Parameters
$name : string

The text string to verify.

Return values
bool

prepareForOutput()

Prepares token content for output to screen.

public static prepareForOutput(string $content[, array<string|int, string> $exclude = [] ]) : string

Replaces invisible characters so they are visible. On non-Windows operating systems it will also colour the invisible characters.

Parameters
$content : string

The content to prepare.

$exclude : array<string|int, string> = []

A list of characters to leave invisible. Can contain \r, \n, \t and a space.

Return values
string

realpath()

CodeSniffer alternative for realpath.

public static realpath(string $path) : string|false

Allows for PHAR support.

Parameters
$path : string

The path to use.

Return values
string|false

stripBasepath()

Removes a base path from the front of a file path.

public static stripBasepath(string $path, string|null $basepath) : string
Parameters
$path : string

The path of the file.

$basepath : string|null

The base path to remove. This should not end with a directory separator.

Return values
string

stripColors()

Strip colors from a text for output to screen.

public static stripColors(string $text) : string
Parameters
$text : string

The text to process.

Return values
string

suggestType()

Returns a valid variable type for param/var tags.

public static suggestType(string $varType) : string

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

Parameters
$varType : string

The variable type to process.

Return values
string

        
On this page

Search results