diff --git a/build/kint.phar b/build/kint.phar index 3bc08f6bc..74ede062d 100644 Binary files a/build/kint.phar and b/build/kint.phar differ diff --git a/psalm.xml b/psalm.xml index 2c50dc061..c781ec2a2 100644 --- a/psalm.xml +++ b/psalm.xml @@ -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" > diff --git a/src/Kint.php b/src/Kint.php index f9e897732..716e4ff89 100644 --- a/src/Kint.php +++ b/src/Kint.php @@ -43,6 +43,8 @@ * Psalm bug #8523 * * @psalm-type KintMode = Kint::MODE_*|bool + * + * @psalm-api */ class Kint implements FacadeInterface { @@ -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'); } @@ -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 = []; diff --git a/src/Parser/ClassStaticsPlugin.php b/src/Parser/ClassStaticsPlugin.php index 813e58283..075d88534 100644 --- a/src/Parser/ClassStaticsPlugin.php +++ b/src/Parser/ClassStaticsPlugin.php @@ -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; diff --git a/src/Parser/ClosurePlugin.php b/src/Parser/ClosurePlugin.php index 14601a90e..f8a29096d 100644 --- a/src/Parser/ClosurePlugin.php +++ b/src/Parser/ClosurePlugin.php @@ -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); diff --git a/src/Parser/EnumPlugin.php b/src/Parser/EnumPlugin.php index e378f911e..f7491641a 100644 --- a/src/Parser/EnumPlugin.php +++ b/src/Parser/EnumPlugin.php @@ -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); diff --git a/src/Parser/MicrotimePlugin.php b/src/Parser/MicrotimePlugin.php index add89e125..cf91e1709 100644 --- a/src/Parser/MicrotimePlugin.php +++ b/src/Parser/MicrotimePlugin.php @@ -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; diff --git a/src/Parser/Parser.php b/src/Parser/Parser.php index d46b0236f..fa8351b3f 100644 --- a/src/Parser/Parser.php +++ b/src/Parser/Parser.php @@ -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); diff --git a/src/Parser/ProfilePlugin.php b/src/Parser/ProfilePlugin.php index 0518688ab..902abc696 100644 --- a/src/Parser/ProfilePlugin.php +++ b/src/Parser/ProfilePlugin.php @@ -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; diff --git a/src/Parser/ProxyPlugin.php b/src/Parser/ProxyPlugin.php index b149d5d3d..e0db1b985 100644 --- a/src/Parser/ProxyPlugin.php +++ b/src/Parser/ProxyPlugin.php @@ -32,6 +32,8 @@ /** * @psalm-import-type ParserTrigger from Parser + * + * @psalm-api */ class ProxyPlugin implements PluginBeginInterface, PluginCompleteInterface { diff --git a/src/Parser/SerializePlugin.php b/src/Parser/SerializePlugin.php index a51088cd2..85293cf42 100644 --- a/src/Parser/SerializePlugin.php +++ b/src/Parser/SerializePlugin.php @@ -32,6 +32,7 @@ use Kint\Value\Representation\ValueRepresentation; use Kint\Value\UninitializedValue; +/** @psalm-api */ class SerializePlugin extends AbstractPlugin implements PluginCompleteInterface { /** diff --git a/src/Parser/SimpleXMLElementPlugin.php b/src/Parser/SimpleXMLElementPlugin.php index ccb7bfc2f..e37997a37 100644 --- a/src/Parser/SimpleXMLElementPlugin.php +++ b/src/Parser/SimpleXMLElementPlugin.php @@ -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; @@ -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); @@ -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); @@ -203,7 +203,6 @@ 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(); @@ -211,7 +210,7 @@ protected function getChildren(ContextInterface $c, SimpleXMLElement $var): arra $contents = []; - foreach ($namespaces as $nsAlias => $nsUrl) { + foreach ($namespaces as $nsAlias => $_) { if ((bool) $nsChildren = $var->children($nsAlias, true)) { $nsap = []; foreach ($nsChildren as $name => $child) { @@ -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; } diff --git a/src/Parser/TracePlugin.php b/src/Parser/TracePlugin.php index 963176674..533456472 100644 --- a/src/Parser/TracePlugin.php +++ b/src/Parser/TracePlugin.php @@ -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)) { diff --git a/src/Parser/XmlPlugin.php b/src/Parser/XmlPlugin.php index 26019c6c6..4b47e62aa 100644 --- a/src/Parser/XmlPlugin.php +++ b/src/Parser/XmlPlugin.php @@ -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); @@ -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 @@ -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) { diff --git a/src/Renderer/AbstractRenderer.php b/src/Renderer/AbstractRenderer.php index ea25e11bd..16a464e33 100644 --- a/src/Renderer/AbstractRenderer.php +++ b/src/Renderer/AbstractRenderer.php @@ -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() { @@ -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; diff --git a/src/Renderer/AssetRendererTrait.php b/src/Renderer/AssetRendererTrait.php index 4c01d6006..11bf9547c 100644 --- a/src/Renderer/AssetRendererTrait.php +++ b/src/Renderer/AssetRendererTrait.php @@ -34,6 +34,7 @@ trait AssetRendererTrait /** @psalm-var array{js?:string, css?:array} */ private static array $assetCache = []; + /** @psalm-api */ public static function renderJs(): string { if (!isset(self::$assetCache['js'])) { @@ -43,6 +44,7 @@ public static function renderJs(): string return self::$assetCache['js']; } + /** @psalm-api */ public static function renderCss(): ?string { if (!isset(self::$theme)) { diff --git a/src/Renderer/PlainRenderer.php b/src/Renderer/PlainRenderer.php index eedb01b3a..6305fa1c8 100644 --- a/src/Renderer/PlainRenderer.php +++ b/src/Renderer/PlainRenderer.php @@ -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); } } diff --git a/src/Renderer/RendererInterface.php b/src/Renderer/RendererInterface.php index e8193e6a7..3c1dbc7b0 100644 --- a/src/Renderer/RendererInterface.php +++ b/src/Renderer/RendererInterface.php @@ -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; diff --git a/src/Renderer/Rich/TablePlugin.php b/src/Renderer/Rich/TablePlugin.php index 74e805bc0..21e86b75e 100644 --- a/src/Renderer/Rich/TablePlugin.php +++ b/src/Renderer/Rich/TablePlugin.php @@ -71,12 +71,9 @@ public function renderTab(RepresentationInterface $r): ?string foreach ($row->getContents() as $field) { $ref = $field->getContext()->isRef() ? '&' : ''; $type = $this->renderer->escape($field->getDisplayType()); - $size = null; $out .= '↧'; } - if (!empty($this->call_info['trace']) && \count($this->call_info['trace']) > 1) { + if (!empty($this->trace) && \count($this->trace) > 1) { $output .= ''; } $output .= $this->calledFrom(); - if (!empty($this->call_info['trace']) && \count($this->call_info['trace']) > 1) { + if (!empty($this->trace) && \count($this->trace) > 1) { $output .= '
    '; - foreach ($this->call_info['trace'] as $index => $step) { + foreach ($this->trace as $index => $step) { if (!$index) { continue; } @@ -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) { diff --git a/src/Utils.php b/src/Utils.php index d37aff3cd..39db543f9 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -107,6 +107,8 @@ final class Utils /** * @codeCoverageIgnore + * + * @psalm-suppress UnusedConstructor */ private function __construct() { diff --git a/src/Value/AbstractValue.php b/src/Value/AbstractValue.php index 79421da4a..b1acb57e5 100644 --- a/src/Value/AbstractValue.php +++ b/src/Value/AbstractValue.php @@ -29,6 +29,7 @@ use Kint\Value\Context\ContextInterface; use Kint\Value\Representation\RepresentationInterface; +use OutOfRangeException; /** * @psalm-import-type ValueName from ContextInterface @@ -103,15 +104,16 @@ public function appendHints(array $hints): void } } + /** @psalm-api */ public function clearHints(): void { $this->hints = []; } - public function addRepresentation(RepresentationInterface $rep, ?int $pos = null): bool + public function addRepresentation(RepresentationInterface $rep, ?int $pos = null): void { if (isset($this->representations[$rep->getName()])) { - return false; + throw new OutOfRangeException('Representation already exists'); } if (null === $pos) { @@ -123,8 +125,6 @@ public function addRepresentation(RepresentationInterface $rep, ?int $pos = null \array_slice($this->representations, $pos) ); } - - return true; } public function replaceRepresentation(RepresentationInterface $rep, ?int $pos = null): void @@ -168,6 +168,7 @@ public function appendRepresentations(array $reps): void } } + /** @psalm-api */ public function clearRepresentations(): void { $this->representations = []; diff --git a/src/Value/ClosureValue.php b/src/Value/ClosureValue.php index 44776154c..fab08fb34 100644 --- a/src/Value/ClosureValue.php +++ b/src/Value/ClosureValue.php @@ -42,7 +42,6 @@ class ClosureValue extends InstanceValue /** @psalm-readonly */ protected ?int $startline; - /** @psalm-param class-string $classname */ public function __construct(ContextInterface $context, Closure $cl) { parent::__construct($context, \get_class($cl), \spl_object_hash($cl), \spl_object_id($cl)); @@ -51,6 +50,8 @@ public function __construct(ContextInterface $context, Closure $cl) $this->addHint('closure'); /** + * @psalm-suppress UnnecessaryVarAnnotation + * * @psalm-var ContextInterface $this->context * Psalm bug #11113 */ @@ -89,11 +90,13 @@ public function __construct(ContextInterface $context, Closure $cl) } } + /** @psalm-api */ public function getFileName(): ?string { return $this->filename; } + /** @psalm-api */ public function getStartLine(): ?int { return $this->startline; diff --git a/src/Value/DateTimeValue.php b/src/Value/DateTimeValue.php index f70ba5539..d7b77282a 100644 --- a/src/Value/DateTimeValue.php +++ b/src/Value/DateTimeValue.php @@ -35,7 +35,6 @@ class DateTimeValue extends InstanceValue /** @psalm-readonly */ protected DateTimeInterface $dt; - /** @psalm-param list $properties */ public function __construct(ContextInterface $context, DateTimeInterface $dt) { parent::__construct($context, \get_class($dt), \spl_object_hash($dt), \spl_object_id($dt)); diff --git a/src/Value/DeclaredCallableBag.php b/src/Value/DeclaredCallableBag.php index 41607b374..e4c7aa661 100644 --- a/src/Value/DeclaredCallableBag.php +++ b/src/Value/DeclaredCallableBag.php @@ -30,6 +30,7 @@ use Kint\Utils; use ReflectionFunctionAbstract; +/** @psalm-api */ final class DeclaredCallableBag { use ParameterHoldingTrait; diff --git a/src/Value/FixedWidthValue.php b/src/Value/FixedWidthValue.php index 82fd81a34..ad1d7e234 100644 --- a/src/Value/FixedWidthValue.php +++ b/src/Value/FixedWidthValue.php @@ -55,7 +55,11 @@ public function __construct(ContextInterface $context, $value) } } - /** @psalm-return FixedWidthType */ + /** + * @psalm-api + * + * @psalm-return FixedWidthType + */ public function getValue() { return $this->value; diff --git a/src/Value/FunctionValue.php b/src/Value/FunctionValue.php index c018e955d..ae9fd0cef 100644 --- a/src/Value/FunctionValue.php +++ b/src/Value/FunctionValue.php @@ -73,6 +73,7 @@ public function getCallableBag(): DeclaredCallableBag return $this->callable_bag; } + /** @psalm-api */ public function getDefinitionRepresentation(): ?CallableDefinitionRepresentation { return $this->definition_rep; diff --git a/src/Value/InstanceValue.php b/src/Value/InstanceValue.php index 509b12bdd..cd5e37ec2 100644 --- a/src/Value/InstanceValue.php +++ b/src/Value/InstanceValue.php @@ -49,10 +49,7 @@ class InstanceValue extends AbstractValue */ protected ?array $children = null; - /** - * @psalm-param class-string $classname - * @psalm-param list $properties - */ + /** @psalm-param class-string $classname */ public function __construct( ContextInterface $context, string $classname, diff --git a/src/Value/MethodValue.php b/src/Value/MethodValue.php index b7b6e0251..0e1908ca3 100644 --- a/src/Value/MethodValue.php +++ b/src/Value/MethodValue.php @@ -97,6 +97,7 @@ public function getCallableBag(): DeclaredCallableBag return $this->callable_bag; } + /** @psalm-api */ public function getDefinitionRepresentation(): ?CallableDefinitionRepresentation { return $this->definition_rep; diff --git a/src/Value/Representation/CallableDefinitionRepresentation.php b/src/Value/Representation/CallableDefinitionRepresentation.php index 17082ec5d..76aa75f32 100644 --- a/src/Value/Representation/CallableDefinitionRepresentation.php +++ b/src/Value/Representation/CallableDefinitionRepresentation.php @@ -88,7 +88,11 @@ public function getClassName(): ?string return $this->classname; } - /** @psalm-return ?non-empty-string */ + /** + * @psalm-api + * + * @psalm-return ?non-empty-string + */ public function getDocstring(): ?string { return $this->docstring; diff --git a/src/Value/Representation/ColorRepresentation.php b/src/Value/Representation/ColorRepresentation.php index b8ff6dcee..4221ccce7 100644 --- a/src/Value/Representation/ColorRepresentation.php +++ b/src/Value/Representation/ColorRepresentation.php @@ -215,7 +215,11 @@ public function getHint(): string return 'color'; } - /** @psalm-return self::COLOR_* */ + /** + * @psalm-api + * + * @psalm-return self::COLOR_* + */ public function getVariant(): int { return $this->variant; diff --git a/src/Value/Representation/MicrotimeRepresentation.php b/src/Value/Representation/MicrotimeRepresentation.php index eca3cc3e3..6a7d300f1 100644 --- a/src/Value/Representation/MicrotimeRepresentation.php +++ b/src/Value/Representation/MicrotimeRepresentation.php @@ -44,8 +44,6 @@ class MicrotimeRepresentation extends AbstractRepresentation protected ?float $total_time; protected ?float $avg_time = null; /** @psalm-readonly */ - protected int $i; - /** @psalm-readonly */ protected int $mem; /** @psalm-readonly */ protected int $mem_real; @@ -64,7 +62,6 @@ public function __construct(int $seconds, int $microseconds, string $group, ?flo $this->group = $group; $this->lap_time = $lap_time; $this->total_time = $total_time; - $this->i = $i; if ($i > 0) { $this->avg_time = $total_time / $i; diff --git a/src/Value/Representation/SourceRepresentation.php b/src/Value/Representation/SourceRepresentation.php index 9dfd2fc86..1645409d1 100644 --- a/src/Value/Representation/SourceRepresentation.php +++ b/src/Value/Representation/SourceRepresentation.php @@ -66,7 +66,11 @@ public function getHint(): string return 'source'; } - /** @psalm-return non-empty-string */ + /** + * @psalm-api + * + * @psalm-return non-empty-string + */ public function getSourceSlice(): string { return \implode("\n", $this->source); diff --git a/src/Value/Representation/SplFileInfoRepresentation.php b/src/Value/Representation/SplFileInfoRepresentation.php index 866848f51..ed6f6d5f5 100644 --- a/src/Value/Representation/SplFileInfoRepresentation.php +++ b/src/Value/Representation/SplFileInfoRepresentation.php @@ -44,7 +44,6 @@ public function __construct(SplFileInfo $fileInfo) $perms = 0; $owner = null; $group = null; - $ctime = null; $mtime = null; $realpath = null; $linktarget = null; @@ -57,7 +56,6 @@ public function __construct(SplFileInfo $fileInfo) $this->size = $fileInfo->getSize(); $owner = $fileInfo->getOwner(); $group = $fileInfo->getGroup(); - $ctime = $fileInfo->getCTime(); $mtime = $fileInfo->getMTime(); $realpath = $fileInfo->getRealPath(); } diff --git a/src/Value/SimpleXMLElementValue.php b/src/Value/SimpleXMLElementValue.php index 9007f9a8b..3d82dd6ad 100644 --- a/src/Value/SimpleXMLElementValue.php +++ b/src/Value/SimpleXMLElementValue.php @@ -32,32 +32,20 @@ class SimpleXMLElementValue extends InstanceValue { - /** - * @psalm-readonly - * - * @psalm-var list - */ - protected array $attributes; - /** @psalm-readonly */ protected ?string $text_content; - /** - * @psalm-param list $children - * @psalm-param list $attributes - */ + /** @psalm-param list $children */ public function __construct( ContextInterface $context, SimpleXMLElement $element, array $children, - array $attributes, ?string $text_content ) { parent::__construct($context, \get_class($element), \spl_object_hash($element), \spl_object_id($element)); $this->addHint('simplexml_element'); $this->children = $children; - $this->attributes = $attributes; $this->text_content = $text_content; } diff --git a/src/Value/SplFileInfoValue.php b/src/Value/SplFileInfoValue.php index 4f203867e..b51a9c971 100644 --- a/src/Value/SplFileInfoValue.php +++ b/src/Value/SplFileInfoValue.php @@ -54,6 +54,7 @@ public function __construct(ContextInterface $context, SplFileInfo $info) } } + /** @psalm-api */ public function getFileSize(): ?int { return $this->filesize; diff --git a/src/Value/StreamValue.php b/src/Value/StreamValue.php index 1febcae13..e88431c91 100644 --- a/src/Value/StreamValue.php +++ b/src/Value/StreamValue.php @@ -62,6 +62,7 @@ public function getDisplayValue(): ?string return $uri; } + /** @psalm-api */ protected function getStreamMeta(): ?array { return $this->stream_meta; diff --git a/src/Value/StringValue.php b/src/Value/StringValue.php index e5b5a8114..ca2c17f46 100644 --- a/src/Value/StringValue.php +++ b/src/Value/StringValue.php @@ -75,6 +75,7 @@ public function getValueUtf8(): string return \mb_convert_encoding($this->value, 'UTF-8', $this->encoding); } + /** @psalm-api */ public function getLength(): int { return $this->length; diff --git a/src/Value/TraceFrameValue.php b/src/Value/TraceFrameValue.php index 959de67c2..d357da3aa 100644 --- a/src/Value/TraceFrameValue.php +++ b/src/Value/TraceFrameValue.php @@ -137,6 +137,7 @@ public function __construct(ArrayValue $old, $raw_frame) } /** + * @psalm-suppress DocblockTypeContradiction * @psalm-suppress RedundantPropertyInitializationCheck * Psalm bug #11124 */ diff --git a/tests/KintTest.php b/tests/KintTest.php index 83aac90c3..a0993ad45 100644 --- a/tests/KintTest.php +++ b/tests/KintTest.php @@ -271,50 +271,40 @@ public function getTriggers(): int */ public function testSetStatesFromCallInfo() { - $r = new TextRenderer(); - $p = new Parser(); - $k = new Kint($p, $r); + $ci1 = ['foo' => 'bar']; + $ci2 = [ + 'modifiers' => ['!', '@', '+'], + 'caller' => [ + 'class' => 'test1234', + ], + ]; - // Set up defaults - $k->setStatesFromStatics([ - 'depth_limit' => 42, - ]); + $r = $this->createMock(TextRenderer::class); + $r->expects($count = $this->exactly(2)) + ->method('setCallInfo') + ->willReturnCallback(function ($param) use ($count, $ci1, $ci2) { + switch ($count->getInvocationCount()) { + case 1: + $this->assertSame($ci1, $param); - $k->setStatesFromCallInfo(['foo' => 'bar']); + return; + case 2: + $this->assertSame($ci2, $param); + + return; + } + }); + + $p = new Parser(42); + $k = new Kint($p, $r); + + $k->setStatesFromCallInfo($ci1); - $this->assertSame(['depth_limit' => 42], $r->getStatics()); - $this->assertSame( - [ - 'params' => null, - 'modifiers' => [], - 'callee' => null, - 'caller' => null, - 'trace' => [], - ], - $r->getCallInfo() - ); $this->assertSame(42, $p->getDepthLimit()); $this->assertNull($p->getCallerClass()); - $k->setStatesFromCallInfo([ - 'modifiers' => ['!', '@', '+'], - 'caller' => [ - 'class' => 'test1234', - ], - ]); + $k->setStatesFromCallInfo($ci2); - $this->assertSame( - [ - 'params' => null, - 'modifiers' => ['!', '@', '+'], - 'callee' => null, - 'caller' => [ - 'class' => 'test1234', - ], - 'trace' => [], - ], - $r->getCallInfo() - ); $this->assertSame(0, $p->getDepthLimit()); $this->assertSame('test1234', $p->getCallerClass()); } diff --git a/tests/Value/AbstractValueTest.php b/tests/Value/AbstractValueTest.php index 68a903d08..367a673ec 100644 --- a/tests/Value/AbstractValueTest.php +++ b/tests/Value/AbstractValueTest.php @@ -31,6 +31,7 @@ use Kint\Value\AbstractValue; use Kint\Value\Context\BaseContext; use Kint\Value\Representation\StringRepresentation; +use OutOfRangeException; /** * @coversNothing @@ -211,7 +212,7 @@ public function testAddRepresentation() $this->assertSame([], $v->getRepresentations()); - $this->assertTrue($v->addRepresentation($r1 = new StringRepresentation('Rep 1', 'contents'))); + $v->addRepresentation($r1 = new StringRepresentation('Rep 1', 'contents')); $this->assertSame( [ 'rep_1' => $r1, @@ -219,15 +220,22 @@ public function testAddRepresentation() $v->getRepresentations() ); - $this->assertFalse($v->addRepresentation($r1)); + $caught = false; + try { + $v->addRepresentation(new StringRepresentation('Rep 1', 'other contents')); + } catch (OutOfRangeException $e) { + $caught = true; + } + $this->assertTrue($caught); $this->assertSame( [ 'rep_1' => $r1, ], $v->getRepresentations() ); + $this->assertSame('contents', $v->getRepresentation('rep_1')->getValue()); - $this->assertTrue($v->addRepresentation($r2 = new StringRepresentation('Rep 2', 'contents'))); + $v->addRepresentation($r2 = new StringRepresentation('Rep 2', 'contents')); $this->assertSame( [ 'rep_1' => $r1, @@ -236,7 +244,7 @@ public function testAddRepresentation() $v->getRepresentations() ); - $this->assertTrue($v->addRepresentation($r3 = new StringRepresentation('Rep 3', 'contents'), 0)); + $v->addRepresentation($r3 = new StringRepresentation('Rep 3', 'contents'), 0); $this->assertSame( [ 'rep_3' => $r3, @@ -246,7 +254,7 @@ public function testAddRepresentation() $v->getRepresentations() ); - $this->assertTrue($v->addRepresentation($r4 = new StringRepresentation('Rep 4', 'contents'), 1)); + $v->addRepresentation($r4 = new StringRepresentation('Rep 4', 'contents'), 1); $this->assertSame( [ 'rep_3' => $r3, @@ -257,7 +265,7 @@ public function testAddRepresentation() $v->getRepresentations() ); - $this->assertTrue($v->addRepresentation($r5 = new StringRepresentation('Rep 5', 'contents'), 100)); + $v->addRepresentation($r5 = new StringRepresentation('Rep 5', 'contents'), 100); $this->assertSame( [ 'rep_3' => $r3, @@ -269,7 +277,7 @@ public function testAddRepresentation() $v->getRepresentations() ); - $this->assertTrue($v->addRepresentation($r6 = new StringRepresentation('Rep 6', 'contents'), -100)); + $v->addRepresentation($r6 = new StringRepresentation('Rep 6', 'contents'), -100); $this->assertSame( [ 'rep_6' => $r6,