[Web] Some minor fixes and improvements for PHP 8
This commit is contained in:
@@ -63,7 +63,7 @@ abstract class AbstractDumper implements DataDumperInterface, DumperInterface
|
||||
*/
|
||||
public function setOutput($output)
|
||||
{
|
||||
$prev = null !== $this->outputStream ? $this->outputStream : $this->lineDumper;
|
||||
$prev = $this->outputStream ?? $this->lineDumper;
|
||||
|
||||
if (\is_callable($output)) {
|
||||
$this->outputStream = null;
|
||||
|
@@ -150,7 +150,7 @@ class CliDumper extends AbstractDumper
|
||||
case is_nan($value): $value = 'NAN'; break;
|
||||
default:
|
||||
$value = (string) $value;
|
||||
if (false === strpos($value, $this->decimalPoint)) {
|
||||
if (!str_contains($value, $this->decimalPoint)) {
|
||||
$value .= $this->decimalPoint.'0';
|
||||
}
|
||||
break;
|
||||
@@ -324,7 +324,7 @@ class CliDumper extends AbstractDumper
|
||||
* @param bool $hasChild When the dump of the hash has child item
|
||||
* @param int $cut The number of items the hash has been cut by
|
||||
*/
|
||||
protected function dumpEllipsis(Cursor $cursor, $hasChild, $cut)
|
||||
protected function dumpEllipsis(Cursor $cursor, bool $hasChild, int $cut)
|
||||
{
|
||||
if ($cut) {
|
||||
$this->line .= ' …';
|
||||
@@ -428,7 +428,7 @@ class CliDumper extends AbstractDumper
|
||||
*
|
||||
* @return string The value with style decoration
|
||||
*/
|
||||
protected function style($style, $value, $attr = [])
|
||||
protected function style(string $style, string $value, array $attr = [])
|
||||
{
|
||||
if (null === $this->colors) {
|
||||
$this->colors = $this->supportsColors();
|
||||
@@ -441,7 +441,7 @@ class CliDumper extends AbstractDumper
|
||||
|
||||
if (isset($attr['ellipsis'], $attr['ellipsis-type'])) {
|
||||
$prefix = substr($value, 0, -$attr['ellipsis']);
|
||||
if ('cli' === \PHP_SAPI && 'path' === $attr['ellipsis-type'] && isset($_SERVER[$pwd = '\\' === \DIRECTORY_SEPARATOR ? 'CD' : 'PWD']) && 0 === strpos($prefix, $_SERVER[$pwd])) {
|
||||
if ('cli' === \PHP_SAPI && 'path' === $attr['ellipsis-type'] && isset($_SERVER[$pwd = '\\' === \DIRECTORY_SEPARATOR ? 'CD' : 'PWD']) && str_starts_with($prefix, $_SERVER[$pwd])) {
|
||||
$prefix = '.'.substr($prefix, \strlen($_SERVER[$pwd]));
|
||||
}
|
||||
if (!empty($attr['ellipsis-tail'])) {
|
||||
@@ -475,7 +475,7 @@ class CliDumper extends AbstractDumper
|
||||
} else {
|
||||
$value = "\033[{$this->styles[$style]}m".$value;
|
||||
}
|
||||
if ($cchrCount && $endCchr === substr($value, -\strlen($endCchr))) {
|
||||
if ($cchrCount && str_ends_with($value, $endCchr)) {
|
||||
$value = substr($value, 0, -\strlen($endCchr));
|
||||
} else {
|
||||
$value .= "\033[{$this->styles['default']}m";
|
||||
|
@@ -56,7 +56,7 @@ final class SourceContextProvider implements ContextProviderInterface
|
||||
$line = $trace[$i]['line'] ?? $line;
|
||||
|
||||
while (++$i < $this->limit) {
|
||||
if (isset($trace[$i]['function'], $trace[$i]['file']) && empty($trace[$i]['class']) && 0 !== strpos($trace[$i]['function'], 'call_user_func')) {
|
||||
if (isset($trace[$i]['function'], $trace[$i]['file']) && empty($trace[$i]['class']) && !str_starts_with($trace[$i]['function'], 'call_user_func')) {
|
||||
$file = $trace[$i]['file'];
|
||||
$line = $trace[$i]['line'];
|
||||
|
||||
@@ -98,7 +98,7 @@ final class SourceContextProvider implements ContextProviderInterface
|
||||
|
||||
if (null !== $this->projectDir) {
|
||||
$context['project_dir'] = $this->projectDir;
|
||||
if (0 === strpos($file, $this->projectDir)) {
|
||||
if (str_starts_with($file, $this->projectDir)) {
|
||||
$context['file_relative'] = ltrim(substr($file, \strlen($this->projectDir)), \DIRECTORY_SEPARATOR);
|
||||
}
|
||||
}
|
||||
|
@@ -116,21 +116,16 @@ class HtmlDumper extends CliDumper
|
||||
|
||||
/**
|
||||
* Sets an HTML header that will be dumped once in the output stream.
|
||||
*
|
||||
* @param string $header An HTML string
|
||||
*/
|
||||
public function setDumpHeader($header)
|
||||
public function setDumpHeader(?string $header)
|
||||
{
|
||||
$this->dumpHeader = $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an HTML prefix and suffix that will encapse every single dump.
|
||||
*
|
||||
* @param string $prefix The prepended HTML string
|
||||
* @param string $suffix The appended HTML string
|
||||
*/
|
||||
public function setDumpBoundaries($prefix, $suffix)
|
||||
public function setDumpBoundaries(string $prefix, string $suffix)
|
||||
{
|
||||
$this->dumpPrefix = $prefix;
|
||||
$this->dumpSuffix = $suffix;
|
||||
@@ -153,7 +148,7 @@ class HtmlDumper extends CliDumper
|
||||
*/
|
||||
protected function getDumpHeader()
|
||||
{
|
||||
$this->headerIsDumped = null !== $this->outputStream ? $this->outputStream : $this->lineDumper;
|
||||
$this->headerIsDumped = $this->outputStream ?? $this->lineDumper;
|
||||
|
||||
if (null !== $this->dumpHeader) {
|
||||
return $this->dumpHeader;
|
||||
@@ -851,7 +846,7 @@ EOHTML
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function style($style, $value, $attr = [])
|
||||
protected function style(string $style, string $value, array $attr = [])
|
||||
{
|
||||
if ('' === $value) {
|
||||
return '';
|
||||
@@ -951,7 +946,7 @@ EOHTML
|
||||
if (-1 === $this->lastDepth) {
|
||||
$this->line = sprintf($this->dumpPrefix, $this->dumpId, $this->indentPad).$this->line;
|
||||
}
|
||||
if ($this->headerIsDumped !== (null !== $this->outputStream ? $this->outputStream : $this->lineDumper)) {
|
||||
if ($this->headerIsDumped !== ($this->outputStream ?? $this->lineDumper)) {
|
||||
$this->line = $this->getDumpHeader().$this->line;
|
||||
}
|
||||
|
||||
@@ -985,7 +980,7 @@ EOHTML
|
||||
}
|
||||
}
|
||||
|
||||
function esc($str)
|
||||
function esc(string $str)
|
||||
{
|
||||
return htmlspecialchars($str, \ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
Reference in New Issue
Block a user