Code-TidyAll
view release on metacpan or search on metacpan
php/PHP_CodeSniffer/src/Util/Common.php view on Meta::CPAN
$eolChar = "\n";
} else {
$eolChar = $matches[0];
}
return $eolChar;
}//end detectLineEndings()
/**
* Check if STDIN is a TTY.
*
* @return boolean
*/
public static function isStdinATTY()
{
// The check is slow (especially calling `tty`) so we static
// cache the result.
static $isTTY = null;
if ($isTTY !== null) {
return $isTTY;
}
if (defined('STDIN') === false) {
return false;
}
// If PHP has the POSIX extensions we will use them.
if (function_exists('posix_isatty') === true) {
$isTTY = (posix_isatty(STDIN) === true);
return $isTTY;
}
// Next try is detecting whether we have `tty` installed and use that.
if (defined('PHP_WINDOWS_VERSION_PLATFORM') === true) {
$devnull = 'NUL';
$which = 'where';
} else {
$devnull = '/dev/null';
$which = 'which';
}
$tty = trim(shell_exec("$which tty 2> $devnull"));
if (empty($tty) === false) {
exec("tty -s 2> $devnull", $output, $returnValue);
$isTTY = ($returnValue === 0);
return $isTTY;
}
// Finally we will use fstat. The solution borrowed from
// https://stackoverflow.com/questions/11327367/detect-if-a-php-script-is-being-run-interactively-or-not
// This doesn't work on Mingw/Cygwin/... using Mintty but they
// have `tty` installed.
$type = [
'S_IFMT' => 0170000,
'S_IFIFO' => 0010000,
];
$stat = fstat(STDIN);
$mode = ($stat['mode'] & $type['S_IFMT']);
$isTTY = ($mode !== $type['S_IFIFO']);
return $isTTY;
}//end isStdinATTY()
/**
* Prepares token content for output to screen.
*
* Replaces invisible characters so they are visible. On non-Windows
* OSes it will also colour the invisible characters.
*
* @param string $content The content to prepare.
* @param string[] $exclude A list of characters to leave invisible.
* Can contain \r, \n, \t and a space.
*
* @return string
*/
public static function prepareForOutput($content, $exclude=[])
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
if (in_array("\r", $exclude, true) === false) {
$content = str_replace("\r", '\r', $content);
}
if (in_array("\n", $exclude, true) === false) {
$content = str_replace("\n", '\n', $content);
}
if (in_array("\t", $exclude, true) === false) {
$content = str_replace("\t", '\t', $content);
}
} else {
if (in_array("\r", $exclude, true) === false) {
$content = str_replace("\r", "\033[30;1m\\r\033[0m", $content);
}
if (in_array("\n", $exclude, true) === false) {
$content = str_replace("\n", "\033[30;1m\\n\033[0m", $content);
}
if (in_array("\t", $exclude, true) === false) {
$content = str_replace("\t", "\033[30;1m\\t\033[0m", $content);
}
if (in_array(' ', $exclude, true) === false) {
$content = str_replace(' ', "\033[30;1m·\033[0m", $content);
}
}//end if
return $content;
}//end prepareForOutput()
/**
* Returns true if the specified string is in the camel caps format.
*
( run in 2.844 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )