PHPCSUtils 1.1.0

FilePath
in package

FinalYes

Helper functions for working with arbitrary file/directory paths.

Typically, these methods are useful for sniffs which examine the name of the file under scan and need to act differently depending on the path in which the file under scan is found.

Tags
see
getFilename

Retrieves the absolute path to the file under scan.

see
getCommandLineData

Can be used to retrieve "basepath" setting.

since
1.1.0

Table of Contents

Methods

getName()  : string
Get the file name of the current file under scan.
isStdin()  : bool
Check whether the input was received via STDIN.
normalizeAbsolutePath()  : string
Normalize an absolute path to forward slashes and to include a trailing slash for directories.
normalizeDirectorySeparators()  : string
Normalize all directory separators to be a forward slash.
startsWith()  : bool
Check whether one file/directory path starts with another path.
trailingSlashIt()  : string
Ensure that a directory path ends on a trailing slash.

Methods

getName()

Get the file name of the current file under scan.

public static getName(File $phpcsFile) : string

In contrast to the PHPCS native getFilename() method, the name returned by this method will have been normalized.

Parameters
$phpcsFile : File

The file being scanned.

Tags
since
1.1.0
Return values
string

The file name without surrounding quotes and with forward slashes as directory separators.

isStdin()

Check whether the input was received via STDIN.

public static isStdin(File $phpcsFile) : bool
Parameters
$phpcsFile : File

The file being scanned.

Tags
since
1.1.0
Return values
bool

normalizeAbsolutePath()

Normalize an absolute path to forward slashes and to include a trailing slash for directories.

public static normalizeAbsolutePath(string $path) : string
Parameters
$path : string

Absolute file or directory path.

Tags
since
1.1.0
Return values
string

normalizeDirectorySeparators()

Normalize all directory separators to be a forward slash.

public static normalizeDirectorySeparators(string $path) : string
Parameters
$path : string

File or directory path.

Tags
since
1.1.0
Return values
string

startsWith()

Check whether one file/directory path starts with another path.

public static startsWith(string $haystack, string $needle) : bool

Recommended to be used only when both paths are absolute.

Note: this function does not normalize paths prior to comparing them. If this is needed, normalization should be done prior to passing the $haystack and $needle parameters to this function.

Also note that this function does a case-sensitive comparison as most OS-es are case-sensitive.

Parameters
$haystack : string

Path to examine.

$needle : string

Partial path which the haystack path should start with.

Tags
since
1.1.0
Return values
bool

trailingSlashIt()

Ensure that a directory path ends on a trailing slash.

public static trailingSlashIt(string $path) : string

Includes safeguard against adding a trailing slash to path ending on a file name.

Parameters
$path : string

File or directory path.

Tags
since
1.1.0
Return values
string

        
On this page

Search results