Skip to content

Commit

Permalink
Replace matchPlugins with array_intersect_key
Browse files Browse the repository at this point in the history
  • Loading branch information
jnvsor committed Aug 26, 2024
1 parent d528bb1 commit c60934c
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 26 deletions.
Binary file modified build/kint.phar
Binary file not shown.
21 changes: 0 additions & 21 deletions src/Renderer/AbstractRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,6 @@ public function postRender(): string
return '';
}

/**
* Returns the first compatible plugin available.
*
* @psalm-param PluginMap $plugins Array of hints to class strings
* @psalm-param array<string, true> $hints Array of object hints
*
* @psalm-return PluginMap Array of hints to class strings filtered and sorted by object hints
*/
public function matchPlugins(array $plugins, array $hints): array
{
$out = [];

foreach ($hints as $key => $_) {
if (isset($plugins[$key])) {
$out[$key] = $plugins[$key];
}
}

return $out;
}

public static function sortPropertiesFull(Value $a, Value $b): int
{
$sort = Value::sortByAccess($a, $b);
Expand Down
6 changes: 3 additions & 3 deletions src/Renderer/RichRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,14 +640,14 @@ protected function renderTab(Value $o, Representation $rep): string
*/
protected function getPlugin(array $plugins, array $hints): ?PluginInterface
{
if ($plugins = $this->matchPlugins($plugins, $hints)) {
$plugin = \end($plugins);
if ($overlap = \array_intersect_key($hints, $plugins)) {
$plugin = $plugins[\array_key_last($overlap)];

if (!isset($this->plugin_objs[$plugin]) && \is_a($plugin, PluginInterface::class, true)) {
$this->plugin_objs[$plugin] = new $plugin($this);
}

return $this->plugin_objs[$plugin] ?? null;
return $this->plugin_objs[$plugin];
}

return null;
Expand Down
4 changes: 2 additions & 2 deletions src/Renderer/TextRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ protected function calledFrom(): string
*/
protected function getPlugin(array $plugins, array $hints): ?PluginInterface
{
if ($plugins = $this->matchPlugins($plugins, $hints)) {
$plugin = \end($plugins);
if ($overlap = \array_intersect_key($hints, $plugins)) {
$plugin = $plugins[\array_key_last($overlap)];

if (!isset($this->plugin_objs[$plugin]) && \is_a($plugin, PluginInterface::class, true)) {
$this->plugin_objs[$plugin] = new $plugin($this);
Expand Down

0 comments on commit c60934c

Please sign in to comment.