Skip to content

Commit

Permalink
Psalm find dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
jnvsor committed Oct 25, 2024
1 parent 39ff4c3 commit 6854b39
Show file tree
Hide file tree
Showing 41 changed files with 130 additions and 150 deletions.
Binary file modified build/kint.phar
Binary file not shown.
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm-baseline.xml"
findUnusedBaselineEntry="true"
findUnusedCode="true"
>
<projectFiles>
<directory name="src" />
Expand Down
6 changes: 4 additions & 2 deletions src/Kint.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
* Psalm bug #8523
*
* @psalm-type KintMode = Kint::MODE_*|bool
*
* @psalm-api
*/
class Kint implements FacadeInterface
{
Expand Down Expand Up @@ -279,7 +281,7 @@ public function dumpAll(array $vars, array $base): string

$output = $this->renderer->preRender();

foreach ($vars as $key => $arg) {
foreach ($vars as $key => $_) {
if (!$base[$key] instanceof ContextInterface) {
throw new InvalidArgumentException('Kint::dumpAll requires all elements of the second argument to be ContextInterface instances');
}
Expand Down Expand Up @@ -458,7 +460,7 @@ public static function getCallInfo(array $aliases, array $trace, array $args): a
$caller = null;
$miniTrace = [];

foreach ($trace as $index => $frame) {
foreach ($trace as $frame) {
if (Utils::traceFrameIsListed($frame, $aliases)) {
$found = true;
$miniTrace = [];
Expand Down
1 change: 0 additions & 1 deletion src/Parser/ClassStaticsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public function parseComplete(&$var, AbstractValue $v, int $trigger): AbstractVa

$class = $v->getClassName();
$parser = $this->getParser();
$pdepth = $parser->getDepthLimit();
$r = new ReflectionClass($class);

$statics_full_name = false;
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/ClosurePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function parseComplete(&$var, AbstractValue $v, int $trigger): AbstractVa

$parser = $this->getParser();

foreach ($statics as $name => $static) {
foreach ($statics as $name => $_) {
$base = new BaseContext('$'.$name);
$base->depth = $cdepth + 1;
$base->reference = null !== ReflectionReference::fromArrayElement($statics, $name);
Expand Down
1 change: 0 additions & 1 deletion src/Parser/EnumPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public function parseComplete(&$var, AbstractValue $v, int $trigger): AbstractVa
return $v;
}

$parser = $this->getParser();
$c = $v->getContext();
$class = \get_class($var);

Expand Down
1 change: 1 addition & 0 deletions src/Parser/MicrotimePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function parseComplete(&$var, AbstractValue $v, int $trigger): AbstractVa
return $v;
}

/** @psalm-api */
public static function clean(): void
{
self::$last = null;
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private function parseArray(array &$var, ContextInterface $c): AbstractValue
return $array;
}

foreach ($var as $key => $val) {
foreach ($var as $key => $_) {
$child = new ArrayContext($key);
$child->depth = $cdepth + 1;
$child->reference = null !== ReflectionReference::fromArrayElement($var, $key);
Expand Down
1 change: 1 addition & 0 deletions src/Parser/ProfilePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use Kint\Value\Representation\ContainerRepresentation;
use Kint\Value\Representation\ProfileRepresentation;

/** @psalm-api */
class ProfilePlugin extends AbstractPlugin implements PluginBeginInterface, PluginCompleteInterface
{
public static bool $profile_value = false;
Expand Down
2 changes: 2 additions & 0 deletions src/Parser/ProxyPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

/**
* @psalm-import-type ParserTrigger from Parser
*
* @psalm-api
*/
class ProxyPlugin implements PluginBeginInterface, PluginCompleteInterface
{
Expand Down
1 change: 1 addition & 0 deletions src/Parser/SerializePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Kint\Value\Representation\ValueRepresentation;
use Kint\Value\UninitializedValue;

/** @psalm-api */
class SerializePlugin extends AbstractPlugin implements PluginCompleteInterface
{
/**
Expand Down
11 changes: 5 additions & 6 deletions src/Parser/SimpleXMLElementPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function parseElement(SimpleXMLElement &$var, ContextInterface $c): Si
$has_children = self::hasChildElements($var);

if ($depthlimit && $has_children) {
$x = new SimpleXMLElementValue($c, $var, [], [], null);
$x = new SimpleXMLElementValue($c, $var, [], null);
$x->addHint('depth_limit');

return $x;
Expand All @@ -103,7 +103,7 @@ protected function parseElement(SimpleXMLElement &$var, ContextInterface $c): Si
$toString = (string) $var;
$string_body = !$has_children && \strlen($toString);

$x = new SimpleXMLElementValue($c, $var, $children, $attributes, \strlen($toString) ? $toString : null);
$x = new SimpleXMLElementValue($c, $var, $children, \strlen($toString) ? $toString : null);

if (self::$verbose) {
$x = $this->methods_plugin->parseComplete($var, $x, Parser::TRIGGER_SUCCESS);
Expand Down Expand Up @@ -146,7 +146,7 @@ protected function getAttributes(ContextInterface $c, SimpleXMLElement $var): ar

$contents = [];

foreach ($namespaces as $nsAlias => $nsUrl) {
foreach ($namespaces as $nsAlias => $_) {
if ((bool) $nsAttribs = $var->attributes($nsAlias, true)) {
foreach ($nsAttribs as $name => $attrib) {
$obj = new ArrayContext($name);
Expand Down Expand Up @@ -203,15 +203,14 @@ protected function getAttributes(ContextInterface $c, SimpleXMLElement $var): ar
*/
protected function getChildren(ContextInterface $c, SimpleXMLElement $var): array
{
$parser = $this->getParser();
$namespaces = \array_merge(['' => null], $var->getDocNamespaces());

$cdepth = $c->getDepth();
$ap = $c->getAccessPath();

$contents = [];

foreach ($namespaces as $nsAlias => $nsUrl) {
foreach ($namespaces as $nsAlias => $_) {
if ((bool) $nsChildren = $var->children($nsAlias, true)) {
$nsap = [];
foreach ($nsChildren as $name => $child) {
Expand Down Expand Up @@ -288,7 +287,7 @@ protected static function hasChildElements(SimpleXMLElement $var): bool
{
$namespaces = \array_merge(['' => null], $var->getDocNamespaces());

foreach ($namespaces as $nsAlias => $nsUrl) {
foreach ($namespaces as $nsAlias => $_) {
if ((array) $var->children($nsAlias, true)) {
return true;
}
Expand Down
4 changes: 0 additions & 4 deletions src/Parser/TracePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ public function parseComplete(&$var, AbstractValue $v, int $trigger): AbstractVa
continue;
}

/**
* @psalm-var TraceFrame $trace[$index]
* Psalm bug #11115
*/
if (isset($trace[$index]['file']) && false !== ($realfile = \realpath($trace[$index]['file']))) {
foreach ($path_blacklist as $path) {
if (0 === \strpos($realfile, $path)) {
Expand Down
4 changes: 4 additions & 0 deletions src/Parser/XmlPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function parseComplete(&$var, AbstractValue $v, int $trigger): AbstractVa
return $v;
}

/** @psalm-suppress PossiblyUnusedMethod */
protected function xmlToSimpleXML(string $var, ContextInterface $c): ?AbstractValue
{
$errors = \libxml_use_internal_errors(true);
Expand Down Expand Up @@ -116,6 +117,8 @@ protected function xmlToSimpleXML(string $var, ContextInterface $c): ?AbstractVa
*
* If it errors loading then we wouldn't have gotten this far in the first place.
*
* @psalm-suppress PossiblyUnusedMethod
*
* @psalm-param non-empty-string $var
*/
protected function xmlToDOMDocument(string $var, ContextInterface $c): ?AbstractValue
Expand Down Expand Up @@ -146,6 +149,7 @@ protected function xmlToDOMDocument(string $var, ContextInterface $c): ?Abstract
return $this->getParser()->parse($xml, $base);
}

/** @psalm-suppress PossiblyUnusedMethod */
protected function xmlToXMLDocument(string $var, ContextInterface $c): ?AbstractValue
{
if (!KINT_PHP84) {
Expand Down
41 changes: 7 additions & 34 deletions src/Renderer/AbstractRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@
*/
abstract class AbstractRenderer implements ConstructableRendererInterface
{
public const SORT_NONE = 0;
public const SORT_VISIBILITY = 1;
public const SORT_FULL = 2;

public static ?string $js_nonce = null;
public static ?string $css_nonce = null;

public bool $show_trace = true;
public bool $render_spl_ids = true;
protected array $call_info = [];
protected array $statics = [];
protected bool $show_trace = true;
protected ?array $callee = null;
protected array $trace = [];

protected bool $render_spl_ids = true;

public function __construct()
{
Expand All @@ -58,39 +55,15 @@ public function shouldRenderObjectIds(): bool

public function setCallInfo(array $info): void
{
if (!\is_array($info['modifiers'] ?? null)) {
$info['modifiers'] = [];
}

if (!\is_array($info['trace'] ?? null)) {
$info['trace'] = [];
}

$this->call_info = [
'params' => $info['params'] ?? null,
'modifiers' => $info['modifiers'],
'callee' => $info['callee'] ?? null,
'caller' => $info['caller'] ?? null,
'trace' => $info['trace'],
];
}

public function getCallInfo(): array
{
return $this->call_info;
$this->callee = $info['callee'] ?? null;
$this->trace = $info['trace'] ?? [];
}

public function setStatics(array $statics): void
{
$this->statics = $statics;
$this->show_trace = !empty($statics['display_called_from']);
}

public function getStatics(): array
{
return $this->statics;
}

public function filterParserPlugins(array $plugins): array
{
return $plugins;
Expand Down
2 changes: 2 additions & 0 deletions src/Renderer/AssetRendererTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ trait AssetRendererTrait
/** @psalm-var array{js?:string, css?:array<path, string>} */
private static array $assetCache = [];

/** @psalm-api */
public static function renderJs(): string
{
if (!isset(self::$assetCache['js'])) {
Expand All @@ -43,6 +44,7 @@ public static function renderJs(): string
return self::$assetCache['js'];
}

/** @psalm-api */
public static function renderCss(): ?string
{
if (!isset(self::$theme)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/PlainRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function setCallInfo(array $info): void
{
parent::setCallInfo($info);

if (\in_array('@', $this->call_info['modifiers'], true)) {
if (\in_array('@', $info['modifiers'], true)) {
$this->setForcePreRender(true);
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/Renderer/RendererInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@ interface RendererInterface
{
public function render(AbstractValue $o): string;

public function setCallInfo(array $info): void;
public function shouldRenderObjectIds(): bool;

public function getCallInfo(): array;
public function setCallInfo(array $info): void;

public function setStatics(array $statics): void;

public function getStatics(): array;

public function shouldRenderObjectIds(): bool;

public function filterParserPlugins(array $plugins): array;

public function preRender(): string;
Expand Down
3 changes: 0 additions & 3 deletions src/Renderer/Rich/TablePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,9 @@ public function renderTab(RepresentationInterface $r): ?string
foreach ($row->getContents() as $field) {
$ref = $field->getContext()->isRef() ? '&amp;' : '';
$type = $this->renderer->escape($field->getDisplayType());
$size = null;

$out .= '<td title="'.$ref.$type;

$title = $ref.$type;

if (null !== ($size = $field->getDisplaySize())) {
$size = $this->renderer->escape($size);
$out .= ' ('.$size.')';
Expand Down
28 changes: 14 additions & 14 deletions src/Renderer/RichRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ public function setCallInfo(array $info): void
{
parent::setCallInfo($info);

if (\in_array('!', $this->call_info['modifiers'], true)) {
if (\in_array('!', $info['modifiers'], true)) {
$this->expand = true;
$this->use_folder = false;
}

if (\in_array('@', $this->call_info['modifiers'], true)) {
if (\in_array('@', $info['modifiers'], true)) {
$this->force_pre_render = true;
}
}
Expand Down Expand Up @@ -420,15 +420,15 @@ public function postRender(): string
$output .= '<span class="kint-folder-trigger" title="Move to folder">&mapstodown;</span>';
}

if (!empty($this->call_info['trace']) && \count($this->call_info['trace']) > 1) {
if (!empty($this->trace) && \count($this->trace) > 1) {
$output .= '<nav></nav>';
}

$output .= $this->calledFrom();

if (!empty($this->call_info['trace']) && \count($this->call_info['trace']) > 1) {
if (!empty($this->trace) && \count($this->trace) > 1) {
$output .= '<ol>';
foreach ($this->call_info['trace'] as $index => $step) {
foreach ($this->trace as $index => $step) {
if (!$index) {
continue;
}
Expand Down Expand Up @@ -492,28 +492,28 @@ protected function calledFrom(): string
{
$output = '';

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

if (
isset($this->call_info['callee']['function']) &&
isset($this->callee['function']) &&
(
!empty($this->call_info['callee']['class']) ||
!empty($this->callee['class']) ||
!\in_array(
$this->call_info['callee']['function'],
$this->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->callee['class'] ?? '';
$output .= $this->callee['type'] ?? '';
$output .= $this->callee['function'].'()]';
}

if ('' !== $output) {
Expand Down
2 changes: 2 additions & 0 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ final class Utils

/**
* @codeCoverageIgnore
*
* @psalm-suppress UnusedConstructor
*/
private function __construct()
{
Expand Down
Loading

0 comments on commit 6854b39

Please sign in to comment.