Skip to content

Commit

Permalink
Merge pull request #8274 from kenjis/update-kint-to-5.1.0
Browse files Browse the repository at this point in the history
chore: update Kint to 5.1.0
  • Loading branch information
kenjis authored Nov 30, 2023
2 parents 93e9c6b + 84903e0 commit ab913e3
Show file tree
Hide file tree
Showing 25 changed files with 101 additions and 64 deletions.
5 changes: 2 additions & 3 deletions system/ThirdParty/Kint/CallFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class CallFinder
/**
* @psalm-param callable-array|callable-string $function
*
* @param mixed $function
* @psalm-return list<array{parameters: list, modifiers: list<PhpToken>}>
*
* @return array List of matching calls on the relevant line
*/
Expand Down Expand Up @@ -187,6 +187,7 @@ public static function getFunctionCalls(string $source, int $line, $function): a
$identifier[T_NAME_RELATIVE] = true;
}

/** @psalm-var list<PhpToken> */
$tokens = \token_get_all($source);
$cursor = 1;
$function_calls = [];
Expand Down Expand Up @@ -449,8 +450,6 @@ private static function realTokenIndex(array $tokens, int $index): ?int
* for `$token[0]` then "..." will incorrectly match the "." operator.
*
* @psalm-param PhpToken $token The token to check
*
* @param mixed $token
*/
private static function tokenIsOperator($token): bool
{
Expand Down
5 changes: 3 additions & 2 deletions system/ThirdParty/Kint/Kint.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Kint implements FacadeInterface
public static $aliases = [
['Kint\\Kint', 'dump'],
['Kint\\Kint', 'trace'],
['Kint\\Kint', 'dumpArray'],
['Kint\\Kint', 'dumpAll'],
];

/**
Expand Down Expand Up @@ -537,7 +537,7 @@ public static function trace()
*
* Functionally equivalent to Kint::dump(1) or Kint::dump(debug_backtrace())
*
* @param mixed ...$args
* @psalm-param array ...$args
*
* @return int|string
*/
Expand Down Expand Up @@ -599,6 +599,7 @@ public static function shortenPath(string $file): string
$match = '/';

foreach (static::$app_root_dirs as $path => $alias) {
/** @psalm-var string $path */
if (empty($path)) {
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion system/ThirdParty/Kint/Parser/BlacklistPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

use Kint\Zval\InstanceValue;
use Kint\Zval\Value;
use Psr\Container\ContainerInterface;

class BlacklistPlugin extends AbstractPlugin
{
Expand All @@ -44,7 +45,7 @@ class BlacklistPlugin extends AbstractPlugin
*
* @var array
*/
public static $shallow_blacklist = ['Psr\\Container\\ContainerInterface'];
public static $shallow_blacklist = [ContainerInterface::class];

public function getTypes(): array
{
Expand Down
2 changes: 1 addition & 1 deletion system/ThirdParty/Kint/Parser/ClosurePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function parse(&$var, Value &$o, int $trigger): void
}

$p = new Representation('Parameters');
$p->contents = &$o->parameters;
$p->contents = $o->parameters;
$o->addRepresentation($p, 0);

$statics = [];
Expand Down
4 changes: 2 additions & 2 deletions system/ThirdParty/Kint/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Parser
* @param int $depth_limit Maximum depth to parse data
* @param ?string $caller Caller class name
*/
public function __construct(int $depth_limit = 0, ?string $caller = null)
public function __construct(int $depth_limit = 0, string $caller = null)
{
$this->marker = "kint\0".\random_bytes(16);

Expand All @@ -83,7 +83,7 @@ public function __construct(int $depth_limit = 0, ?string $caller = null)
/**
* Set the caller class.
*/
public function setCallerClass(?string $caller = null): void
public function setCallerClass(string $caller = null): void
{
$this->noRecurseCall();

Expand Down
2 changes: 1 addition & 1 deletion system/ThirdParty/Kint/Parser/PluginInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getTypes(): array;
public function getTriggers(): int;

/**
* @param mixed &$var
* @psalm-param mixed &$var
*/
public function parse(&$var, Value &$o, int $trigger): void;
}
6 changes: 6 additions & 0 deletions system/ThirdParty/Kint/Parser/TablePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
use Kint\Zval\Representation\Representation;
use Kint\Zval\Value;

// Note: Interaction with ArrayLimitPlugin:
// Any array limited children will be shown in tables identically to
// non-array-limited children since the table only shows that it is an array
// and it's size anyway. Because ArrayLimitPlugin halts the parse on finding
// a limit all other plugins including this one are stopped, so you cannot get
// a tabular representation of an array that is longer than the limit.
class TablePlugin extends AbstractPlugin
{
public function getTypes(): array
Expand Down
76 changes: 49 additions & 27 deletions system/ThirdParty/Kint/Renderer/RichRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ class RichRenderer extends AbstractRenderer
*/
public static $sort = self::SORT_NONE;

/**
* Timestamp to print in footer in date() format.
*
* @var ?string
*/
public static $timestamp = null;

public static $needs_pre_render = true;
public static $needs_folder_render = true;

Expand Down Expand Up @@ -465,29 +472,7 @@ public function postRender(): string
$output .= '<nav></nav>';
}

if (isset($this->call_info['callee']['file'])) {
$output .= 'Called from '.$this->ideLink(
$this->call_info['callee']['file'],
$this->call_info['callee']['line']
);
}

if (
isset($this->call_info['callee']['function']) &&
(
!empty($this->call_info['callee']['class']) ||
!\in_array(
$this->call_info['callee']['function'],
['include', 'include_once', 'require', 'require_once'],
true
)
)
) {
$output .= ' [';
$output .= $this->call_info['callee']['class'] ?? '';
$output .= $this->call_info['callee']['type'] ?? '';
$output .= $this->call_info['callee']['function'].'()]';
}
$output .= $this->calledFrom();

if (!empty($this->call_info['trace']) && \count($this->call_info['trace']) > 1) {
$output .= '<ol>';
Expand All @@ -497,8 +482,8 @@ public function postRender(): string
}

$output .= '<li>'.$this->ideLink($step['file'], $step['line']); // closing tag not required
if (isset($step['function'])
&& !\in_array($step['function'], ['include', 'include_once', 'require', 'require_once'], true)
if (isset($step['function']) &&
!\in_array($step['function'], ['include', 'include_once', 'require', 'require_once'], true)
) {
$output .= ' [';
$output .= $step['class'] ?? '';
Expand All @@ -516,8 +501,6 @@ public function postRender(): string

/**
* @psalm-param Encoding $encoding
*
* @param mixed $encoding
*/
public function escape(string $string, $encoding = false): string
{
Expand Down Expand Up @@ -559,6 +542,45 @@ public function ideLink(string $file, int $line): string
return '<a '.$class.'href="'.$this->escape($ideLink).'">'.$path.'</a>';
}

protected function calledFrom(): string
{
$output = '';

if (isset($this->call_info['callee']['file'])) {
$output .= ' '.$this->ideLink(
$this->call_info['callee']['file'],
$this->call_info['callee']['line']
);
}

if (
isset($this->call_info['callee']['function']) &&
(
!empty($this->call_info['callee']['class']) ||
!\in_array(
$this->call_info['callee']['function'],
['include', 'include_once', 'require', 'require_once'],
true
)
)
) {
$output .= ' [';
$output .= $this->call_info['callee']['class'] ?? '';
$output .= $this->call_info['callee']['type'] ?? '';
$output .= $this->call_info['callee']['function'].'()]';
}

if ('' !== $output) {
$output = 'Called from'.$output;
}

if (null !== self::$timestamp) {
$output .= ' '.\date(self::$timestamp);
}

return $output;
}

protected function renderTab(Value $o, Representation $rep): string
{
if (($plugin = $this->getPlugin(self::$tab_plugins, $rep->hints)) && $plugin instanceof TabPluginInterface) {
Expand Down
2 changes: 1 addition & 1 deletion system/ThirdParty/Kint/Renderer/Text/AbstractPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(TextRenderer $r)
$this->renderer = $r;
}

public function renderLockedHeader(Value $o, ?string $content = null): string
public function renderLockedHeader(Value $o, string $content = null): string
{
$out = '';

Expand Down
18 changes: 15 additions & 3 deletions system/ThirdParty/Kint/Renderer/TextRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ class TextRenderer extends AbstractRenderer
*/
public static $sort = self::SORT_NONE;

/**
* Timestamp to print in footer in date() format.
*
* @var ?string
*/
public static $timestamp = null;

public $header_width = 80;
public $indent_width = 4;

Expand Down Expand Up @@ -300,7 +307,7 @@ public function filterParserPlugins(array $plugins): array
{
$return = [];

foreach ($plugins as $index => $plugin) {
foreach ($plugins as $plugin) {
foreach (self::$parser_plugin_whitelist as $whitelist) {
if ($plugin instanceof $whitelist) {
$return[] = $plugin;
Expand All @@ -319,8 +326,6 @@ public function ideLink(string $file, int $line): string

/**
* @psalm-param Encoding $encoding
*
* @param mixed $encoding
*/
public function escape(string $string, $encoding = false): string
{
Expand Down Expand Up @@ -355,6 +360,13 @@ protected function calledFrom(): string
$output .= $this->call_info['callee']['function'].'()]';
}

if (null !== self::$timestamp) {
if (\strlen($output)) {
$output .= ' ';
}
$output .= \date(self::$timestamp);
}

return $output;
}

Expand Down
2 changes: 0 additions & 2 deletions system/ThirdParty/Kint/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,6 @@ public static function normalizeAliases(array &$aliases): void

/**
* @psalm-param Encoding $encoding
*
* @param mixed $encoding
*/
public static function truncateString(string $input, int $length = PHP_INT_MAX, string $end = '...', $encoding = false): string
{
Expand Down
6 changes: 1 addition & 5 deletions system/ThirdParty/Kint/Zval/BlobValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ public function transplant(Value $old): void

/**
* @psalm-param Encoding $encoding
*
* @param mixed $encoding
*/
public static function strlen(string $string, $encoding = false): int
{
Expand All @@ -142,10 +140,8 @@ public static function strlen(string $string, $encoding = false): int

/**
* @psalm-param Encoding $encoding
*
* @param mixed $encoding
*/
public static function substr(string $string, int $start, ?int $length = null, $encoding = false): string
public static function substr(string $string, int $start, int $length = null, $encoding = false): string
{
if (\function_exists('mb_substr')) {
if (false === $encoding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function __construct(string $value)
$this->setValues($value);
}

public function getColor(?int $variant = null): ?string
public function getColor(int $variant = null): ?string
{
if (!$variant) {
$variant = $this->variant;
Expand Down Expand Up @@ -275,7 +275,7 @@ public function getColor(?int $variant = null): ?string
return null;
}

public function hasAlpha(?int $variant = null): bool
public function hasAlpha(int $variant = null): bool
{
if (null === $variant) {
$variant = $this->variant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MicrotimeRepresentation extends Representation
public $mem_peak_real = 0;
public $hints = ['microtime'];

public function __construct(int $seconds, int $microseconds, int $group, ?float $lap = null, ?float $total = null, int $i = 0)
public function __construct(int $seconds, int $microseconds, int $group, float $lap = null, float $total = null, int $i = 0)
{
parent::__construct('Microtime');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Representation

protected $name;

public function __construct(string $label, ?string $name = null)
public function __construct(string $label, string $name = null)
{
$this->label = $label;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(string $filename, int $line, int $padding = 7)
* @param int $start_line The first line to display (1 based)
* @param null|int $length Amount of lines to show
*/
public static function getSource(string $filename, int $start_line = 1, ?int $length = null): ?array
public static function getSource(string $filename, int $start_line = 1, int $length = null): ?array
{
if (!$filename || !\file_exists($filename) || !\is_readable($filename)) {
return null;
Expand Down
8 changes: 4 additions & 4 deletions system/ThirdParty/Kint/Zval/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ class Value
public $reference = false;
public $depth = 0;
public $size;
public $value;
public $hints = [];
public $value;

protected $representations = [];

public function __construct()
{
}

public function addRepresentation(Representation $rep, ?int $pos = null): bool
public function addRepresentation(Representation $rep, int $pos = null): bool
{
if (isset($this->representations[$rep->getName()])) {
return false;
Expand All @@ -81,7 +81,7 @@ public function addRepresentation(Representation $rep, ?int $pos = null): bool
return true;
}

public function replaceRepresentation(Representation $rep, ?int $pos = null): void
public function replaceRepresentation(Representation $rep, int $pos = null): void
{
if (null === $pos) {
$this->representations[$rep->getName()] = $rep;
Expand Down Expand Up @@ -234,7 +234,7 @@ public function transplant(self $old): void
/**
* Creates a new basic object with a name and access path.
*/
public static function blank(?string $name = null, ?string $access_path = null): self
public static function blank(string $name = null, string $access_path = null): self
{
$o = new self();
$o->name = $name;
Expand Down
Loading

0 comments on commit ab913e3

Please sign in to comment.