Skip to content

Commit

Permalink
Merge pull request #6893 from kenjis/update-kint-5.0
Browse files Browse the repository at this point in the history
Update Kint to 5.0.1
  • Loading branch information
samsonasik authored Nov 22, 2022
2 parents 6ae80be + b86b13c commit aa1771e
Show file tree
Hide file tree
Showing 102 changed files with 1,723 additions and 1,190 deletions.
2 changes: 1 addition & 1 deletion admin/framework/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"psr/log": "^1.1"
},
"require-dev": {
"kint-php/kint": "^4.2",
"kint-php/kint": "^5.0.1",
"codeigniter/coding-standard": "^1.5",
"fakerphp/faker": "^1.9",
"friendsofphp/php-cs-fixer": "~3.13.0",
Expand Down
4 changes: 2 additions & 2 deletions app/Config/Kint.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Config;

use CodeIgniter\Config\BaseConfig;
use Kint\Renderer\Renderer;
use Kint\Renderer\AbstractRenderer;

/**
* --------------------------------------------------------------------------
Expand Down Expand Up @@ -35,7 +35,7 @@ class Kint extends BaseConfig
*/
public string $richTheme = 'aante-light.css';
public bool $richFolder = false;
public int $richSort = Renderer::SORT_FULL;
public int $richSort = AbstractRenderer::SORT_FULL;
public $richObjectPlugins;
public $richTabPlugins;

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"psr/log": "^1.1"
},
"require-dev": {
"kint-php/kint": "^4.2",
"kint-php/kint": "^5.0.1",
"codeigniter/coding-standard": "^1.5",
"fakerphp/faker": "^1.9",
"friendsofphp/php-cs-fixer": "~3.13.0",
Expand Down
94 changes: 73 additions & 21 deletions system/ThirdParty/Kint/CallFinder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* The MIT License (MIT)
*
Expand All @@ -25,6 +27,10 @@

namespace Kint;

/**
* @psalm-type PhpTokenArray = array{int, string, int}
* @psalm-type PhpToken = string|PhpTokenArray
*/
class CallFinder
{
private static $ignore = [
Expand Down Expand Up @@ -88,6 +94,7 @@ class CallFinder
T_XOR_EQUAL => true,
T_POW => true,
T_POW_EQUAL => true,
T_SPACESHIP => true,
T_DOUBLE_ARROW => true,
'!' => true,
'%' => true,
Expand Down Expand Up @@ -128,7 +135,14 @@ class CallFinder
T_STRING => true,
];

public static function getFunctionCalls($source, $line, $function)
/**
* @psalm-param callable-array|callable-string $function
*
* @param mixed $function
*
* @return array List of matching calls on the relevant line
*/
public static function getFunctionCalls(string $source, int $line, $function): array
{
static $up = [
'(' => true,
Expand All @@ -155,11 +169,8 @@ public static function getFunctionCalls($source, $line, $function)
T_NS_SEPARATOR => true,
];

if (KINT_PHP70) {
self::$operator[T_SPACESHIP] = true;
}

if (KINT_PHP74) {
self::$operator[T_FN] = true;
self::$operator[T_COALESCE_EQUAL] = true;
}

Expand All @@ -179,7 +190,9 @@ public static function getFunctionCalls($source, $line, $function)
$tokens = \token_get_all($source);
$cursor = 1;
$function_calls = [];

// Performance optimization preventing backwards loops
/** @psalm-var array<PhpToken|null> */
$prev_tokens = [null, null, null];

if (\is_array($function)) {
Expand All @@ -188,6 +201,9 @@ public static function getFunctionCalls($source, $line, $function)
$function = \strtolower($function[1]);
} else {
$class = null;
/**
* @psalm-suppress RedundantFunctionCallGivenDocblockType
*/
$function = \strtolower($function);
}

Expand Down Expand Up @@ -243,8 +259,8 @@ public static function getFunctionCalls($source, $line, $function)
continue;
}

/** @var array{int, string, int} $prev_tokens[0] */
// All self::$namespace tokens are T_ constants
/** @psalm-var PhpTokenArray $prev_tokens[0] */
$ns = \explode('\\', \strtolower($prev_tokens[0][1]));

if (\end($ns) !== $class) {
Expand Down Expand Up @@ -350,6 +366,7 @@ public static function getFunctionCalls($source, $line, $function)
// Format the final output parameters
foreach ($params as &$param) {
$name = self::tokensFormatted($param['short']);

$expression = false;
foreach ($name as $token) {
if (self::tokenIsOperator($token)) {
Expand All @@ -365,6 +382,12 @@ public static function getFunctionCalls($source, $line, $function)
];
}

// Skip first-class callables
/** @psalm-var list<array{name: string, path: string, expression: bool}> $params */
if (KINT_PHP81 && 1 === \count($params) && '...' === \reset($params)['path']) {
continue;
}

// Get the modifiers
--$index;

Expand Down Expand Up @@ -402,7 +425,10 @@ public static function getFunctionCalls($source, $line, $function)
return $function_calls;
}

private static function realTokenIndex(array $tokens, $index)
/**
* @psalm-param PhpToken[] $tokens
*/
private static function realTokenIndex(array $tokens, int $index): ?int
{
++$index;

Expand All @@ -422,31 +448,37 @@ private static function realTokenIndex(array $tokens, $index)
* occasionally add "..." to short parameter versions. If we simply check
* for `$token[0]` then "..." will incorrectly match the "." operator.
*
* @param array|string $token The token to check
* @psalm-param PhpToken $token The token to check
*
* @return bool
* @param mixed $token
*/
private static function tokenIsOperator($token)
private static function tokenIsOperator($token): bool
{
return '...' !== $token && isset(self::$operator[$token[0]]);
}

private static function tokensToString(array $tokens)
/**
* @psalm-param PhpToken[] $tokens
*/
private static function tokensToString(array $tokens): string
{
$out = '';

foreach ($tokens as $token) {
if (\is_string($token)) {
$out .= $token;
} elseif (\is_array($token)) {
} else {
$out .= $token[1];
}
}

return $out;
}

private static function tokensTrim(array $tokens)
/**
* @psalm-param PhpToken[] $tokens
*/
private static function tokensTrim(array $tokens): array
{
foreach ($tokens as $index => $token) {
if (isset(self::$ignore[$token[0]])) {
Expand All @@ -469,32 +501,52 @@ private static function tokensTrim(array $tokens)
return \array_reverse($tokens);
}

private static function tokensFormatted(array $tokens)
/**
* @psalm-param PhpToken[] $tokens
*
* @psalm-return PhpToken[]
*/
private static function tokensFormatted(array $tokens): array
{
$space = false;
$attribute = false;

$tokens = self::tokensTrim($tokens);

$space = false;
$attribute = false;
// Keep space between "strip" symbols for different behavior for matches or closures
// Normally we want to strip spaces between strip tokens: $x{...}[...]
// However with closures and matches we don't: function (...) {...}
$ignorestrip = false;
$output = [];
$last = null;

if (T_FUNCTION === $tokens[0][0] ||
(KINT_PHP74 && T_FN === $tokens[0][0]) ||
(KINT_PHP80 && T_MATCH === $tokens[0][0])
) {
$ignorestrip = true;
}

foreach ($tokens as $index => $token) {
if (isset(self::$ignore[$token[0]])) {
if ($space) {
continue;
}

$next = $tokens[self::realTokenIndex($tokens, $index)];
$next = self::realTokenIndex($tokens, $index);
if (null === $next) {
// This should be impossible, since we always call tokensTrim first
break; // @codeCoverageIgnore
}
$next = $tokens[$next];

/** @var array|string $last */
/** @psalm-var PhpToken $last */
if ($attribute && ']' === $last[0]) {
$attribute = false;
} elseif (isset(self::$strip[$last[0]]) && !self::tokenIsOperator($next)) {
} elseif (!$ignorestrip && isset(self::$strip[$last[0]]) && !self::tokenIsOperator($next)) {
continue;
}

if (isset(self::$strip[$next[0]]) && $last && !self::tokenIsOperator($last)) {
if (!$ignorestrip && isset(self::$strip[$next[0]]) && $last && !self::tokenIsOperator($last)) {
continue;
}

Expand Down
49 changes: 49 additions & 0 deletions system/ThirdParty/Kint/FacadeInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt ([email protected]), Rokas Šleinius ([email protected])
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

namespace Kint;

use Kint\Parser\Parser;
use Kint\Renderer\RendererInterface;
use Kint\Zval\Value;

interface FacadeInterface
{
public function __construct(Parser $p, RendererInterface $r);

public function setStatesFromStatics(array $statics): void;

public function setStatesFromCallInfo(array $info): void;

/**
* Renders a list of vars including the pre and post renders.
*
* @param array $vars Data to dump
* @param Value[] $base The base value objects
*/
public function dumpAll(array $vars, array $base): string;
}
Loading

0 comments on commit aa1771e

Please sign in to comment.