diff --git a/build/kint.phar b/build/kint.phar index ddd666fe9..0a41abd8d 100644 Binary files a/build/kint.phar and b/build/kint.phar differ diff --git a/src/CallFinder.php b/src/CallFinder.php index f85b1ae01..cfa1921ac 100644 --- a/src/CallFinder.php +++ b/src/CallFinder.php @@ -248,15 +248,15 @@ public static function getFunctionCalls(string $source, int $line, $function): a // Check if it matches the signature if (null === $class) { - if ($prev_tokens[1] && isset(self::$classcalls[$prev_tokens[1][0]])) { + if (null !== $prev_tokens[1] && isset(self::$classcalls[$prev_tokens[1][0]])) { continue; } } else { - if (!$prev_tokens[1] || T_DOUBLE_COLON !== $prev_tokens[1][0]) { + if (null === $prev_tokens[1] || T_DOUBLE_COLON !== $prev_tokens[1][0]) { continue; } - if (!$prev_tokens[0] || !isset(self::$namespace[$prev_tokens[0][0]])) { + if (null === $prev_tokens[0] || !isset(self::$namespace[$prev_tokens[0][0]])) { continue; } @@ -539,20 +539,21 @@ private static function tokensFormatted(array $tokens): array $next = $tokens[$next]; /** @psalm-var PhpToken $last */ + // Since we call tokensTrim we know we can't be here without a $last */ if ($attribute && ']' === $last[0]) { $attribute = false; } elseif (!$ignorestrip && isset(self::$strip[$last[0]]) && !self::tokenIsOperator($next)) { continue; } - if (!$ignorestrip && isset(self::$strip[$next[0]]) && $last && !self::tokenIsOperator($last)) { + if (!$ignorestrip && isset(self::$strip[$next[0]]) && !self::tokenIsOperator($last)) { continue; } $token = ' '; $space = true; } else { - if (KINT_PHP80 && $last && T_ATTRIBUTE == $last[0]) { + if (KINT_PHP80 && null !== $last && T_ATTRIBUTE == $last[0]) { $attribute = true; } diff --git a/src/Kint.php b/src/Kint.php index 40d37689b..614731939 100644 --- a/src/Kint.php +++ b/src/Kint.php @@ -411,6 +411,8 @@ public static function getBasesFromParamInfo(array $params, int $argc): array * @param array $args Arguments * * @return array Call info + * + * @psalm-param list $trace */ public static function getCallInfo(array $aliases, array $trace, array $args): array { @@ -456,7 +458,7 @@ public static function getCallInfo(array $aliases, array $trace, array $args): a 'trace' => $miniTrace, ]; - if ($call) { + if (null !== $call) { $ret['params'] = $call['parameters']; $ret['modifiers'] = $call['modifiers']; } @@ -648,7 +650,7 @@ protected static function getSingleCall(array $frame, array $args): ?array if ( !isset($frame['file'], $frame['line'], $frame['function']) || !\is_readable($frame['file']) || - !$source = \file_get_contents($frame['file']) + false === ($source = \file_get_contents($frame['file'])) ) { return null; } diff --git a/src/Parser/ClassMethodsPlugin.php b/src/Parser/ClassMethodsPlugin.php index e71d537aa..8b90300ae 100644 --- a/src/Parser/ClassMethodsPlugin.php +++ b/src/Parser/ClassMethodsPlugin.php @@ -61,6 +61,7 @@ public function parse(&$var, Value &$o, int $trigger): void $methods[] = new MethodValue($method); } + /** @psalm-suppress InvalidArgument */ \usort($methods, ['Kint\\Parser\\ClassMethodsPlugin', 'sort']); self::$cache[$class] = $methods; @@ -68,6 +69,7 @@ public function parse(&$var, Value &$o, int $trigger): void if (!empty(self::$cache[$class])) { $rep = new Representation('Available methods', 'methods'); + $rep->contents = []; // Can't cache access paths foreach (self::$cache[$class] as $m) { diff --git a/src/Parser/ClassStaticsPlugin.php b/src/Parser/ClassStaticsPlugin.php index 5435da932..5a063b1d3 100644 --- a/src/Parser/ClassStaticsPlugin.php +++ b/src/Parser/ClassStaticsPlugin.php @@ -87,6 +87,7 @@ public function parse(&$var, Value &$o, int $trigger): void $const->access_path = '\\'.$class.'::'.$name; } + /** @psalm-var Value */ $const = $this->parser->parse($val, $const); $consts[] = $const; @@ -96,7 +97,8 @@ public function parse(&$var, Value &$o, int $trigger): void } $statics = new Representation('Static class properties', 'statics'); - $statics->contents = self::$cache[$class]; + /** @psalm-var list */ + $statics->contents = self::$cache[$class] ?? []; foreach ($reflection->getProperties(ReflectionProperty::IS_STATIC) as $static) { $prop = new Value(); @@ -124,6 +126,7 @@ public function parse(&$var, Value &$o, int $trigger): void $statics->contents[] = $prop; } else { $static = $static->getValue(); + /** @psalm-var Value */ $statics->contents[] = $this->parser->parse($static, $prop); } } @@ -132,6 +135,7 @@ public function parse(&$var, Value &$o, int $trigger): void return; } + /** @psalm-suppress InvalidArgument */ \usort($statics->contents, ['Kint\\Parser\\ClassStaticsPlugin', 'sort']); $o->addRepresentation($statics); diff --git a/src/Parser/DOMDocumentPlugin.php b/src/Parser/DOMDocumentPlugin.php index 84cfbf835..90afb91ab 100644 --- a/src/Parser/DOMDocumentPlugin.php +++ b/src/Parser/DOMDocumentPlugin.php @@ -154,6 +154,7 @@ protected function parseList($var, InstanceValue &$o, int $trigger): void } $r = new Representation('Iterator'); + $r->contents = []; $o->replaceRepresentation($r, 0); foreach ($var as $key => $item) { @@ -222,6 +223,7 @@ protected function parseNode(DOMNode $var, InstanceValue &$o): void $attributes = null; $rep = $o->value; + $rep->contents = []; foreach ($known_properties as $prop) { $prop_obj = $this->parseProperty($o, $prop, $var); @@ -250,15 +252,14 @@ protected function parseNode(DOMNode $var, InstanceValue &$o): void // Set the attributes if ($attributes) { $a = new Representation('Attributes'); - foreach ($attributes->contents as $attribute) { - $a->contents[] = $attribute; - } + $a->contents = $attributes->contents; $o->addRepresentation($a, 0); } // Set the children - if ($childNodes) { + if ($childNodes && \is_array($childNodes->contents)) { $c = new Representation('Children'); + $c->contents = []; if (1 === \count($childNodes->contents) && ($node = \reset($childNodes->contents)) && \in_array('depth_limit', $node->hints, true)) { $n = new InstanceValue(); @@ -278,9 +279,7 @@ protected function parseNode(DOMNode $var, InstanceValue &$o): void } $o->addRepresentation($c, 0); - } - if ($childNodes) { $o->size = \count($childNodes->contents); } diff --git a/src/Parser/Parser.php b/src/Parser/Parser.php index 1767eaa3f..7e4d14355 100644 --- a/src/Parser/Parser.php +++ b/src/Parser/Parser.php @@ -321,6 +321,7 @@ private function parseArray(array &$var, Value $o): Value } $rep = new Representation('Contents'); + $rep->contents = []; $rep->implicit_label = true; $array->addRepresentation($rep); $array->value = $rep; @@ -442,6 +443,7 @@ private function parseObject(&$var, Value $o): Value } $rep = new Representation('Properties'); + $rep->contents = []; $readonly = []; diff --git a/src/Parser/SimpleXMLElementPlugin.php b/src/Parser/SimpleXMLElementPlugin.php index db6f9b9c1..275f4f282 100644 --- a/src/Parser/SimpleXMLElementPlugin.php +++ b/src/Parser/SimpleXMLElementPlugin.php @@ -79,6 +79,7 @@ public function parse(&$var, Value &$o, int $trigger): void // Attributes $a = new Representation('Attributes'); + $a->contents = []; $base_obj = new Value(); $base_obj->depth = $x->depth; @@ -96,6 +97,7 @@ public function parse(&$var, Value &$o, int $trigger): void $attribs = []; foreach ($namespaces as $nsAlias => $nsUrl) { + /** @psalm-suppress RiskyTruthyFalsyComparison */ if ($nsAttribs = $var->attributes($nsUrl)) { $cleanAttribs = []; foreach ($nsAttribs as $name => $attrib) { @@ -131,6 +133,7 @@ public function parse(&$var, Value &$o, int $trigger): void // Children $c = new Representation('Children'); + $c->contents = []; foreach ($namespaces as $nsAlias => $nsUrl) { // This is doubling items because of the root namespace @@ -140,6 +143,7 @@ public function parse(&$var, Value &$o, int $trigger): void continue; } + /** @psalm-suppress RiskyTruthyFalsyComparison */ if ($nsChildren = $var->children($nsUrl)) { $nsap = []; foreach ($nsChildren as $name => $child) { diff --git a/src/Parser/TracePlugin.php b/src/Parser/TracePlugin.php index a5f47dcfc..c699e20c9 100644 --- a/src/Parser/TracePlugin.php +++ b/src/Parser/TracePlugin.php @@ -82,7 +82,7 @@ public function parse(&$var, Value &$o, int $trigger): void continue; } - if (isset($trace[$index]['file']) && ($realfile = \realpath($trace[$index]['file']))) { + if (isset($trace[$index]['file']) && false !== ($realfile = \realpath($trace[$index]['file']))) { foreach ($path_blacklist as $path) { if (0 === \strpos($realfile, $path)) { continue 2; diff --git a/src/Parser/XmlPlugin.php b/src/Parser/XmlPlugin.php index a5a31abd4..a17977654 100644 --- a/src/Parser/XmlPlugin.php +++ b/src/Parser/XmlPlugin.php @@ -124,7 +124,7 @@ protected static function xmlToSimpleXML(string $var, ?string $parent_path): ?ar protected static function xmlToDOMDocument(string $var, ?string $parent_path): ?array { // There's no way to check validity in DOMDocument without making errors. For shame! - if (!self::xmlToSimpleXML($var, $parent_path)) { + if (null === self::xmlToSimpleXML($var, $parent_path)) { return null; } diff --git a/src/Renderer/CliRenderer.php b/src/Renderer/CliRenderer.php index c2ea103b6..774b34743 100644 --- a/src/Renderer/CliRenderer.php +++ b/src/Renderer/CliRenderer.php @@ -71,6 +71,7 @@ class CliRenderer extends TextRenderer protected static $terminal_width = null; + /** @var bool */ protected $windows_output = false; protected $colors = false; @@ -100,7 +101,10 @@ public function __construct() if (!self::$terminal_width) { if (!KINT_WIN && self::$detect_width) { try { - self::$terminal_width = (int) \exec('tput cols'); + $tput = \exec('tput cols'); + if (false !== $tput) { + self::$terminal_width = (int) $tput; + } } catch (Throwable $t) { self::$terminal_width = self::$default_width; } diff --git a/src/Renderer/Rich/AbstractPlugin.php b/src/Renderer/Rich/AbstractPlugin.php index 4d9ec7067..082976c74 100644 --- a/src/Renderer/Rich/AbstractPlugin.php +++ b/src/Renderer/Rich/AbstractPlugin.php @@ -50,7 +50,7 @@ public function renderLockedHeader(Value $o, string $content): string { $header = '
'; - if (RichRenderer::$access_paths && $o->depth > 0 && $ap = $o->getAccessPath()) { + if (RichRenderer::$access_paths && $o->depth > 0 && null !== ($ap = $o->getAccessPath())) { $header .= ''; } diff --git a/src/Renderer/Rich/CallablePlugin.php b/src/Renderer/Rich/CallablePlugin.php index 744380524..8ca45399b 100644 --- a/src/Renderer/Rich/CallablePlugin.php +++ b/src/Renderer/Rich/CallablePlugin.php @@ -74,7 +74,7 @@ protected function renderMethod(MethodValue $o): string $header .= ''.$s; if ($o->return_reference) { - if ($s) { + if (\is_string($s) && \strlen($s)) { $header .= ' '; } $header .= $this->renderer->escape('&'); diff --git a/src/Renderer/Rich/MethodDefinitionPlugin.php b/src/Renderer/Rich/MethodDefinitionPlugin.php index f5ed37b62..f137300ad 100644 --- a/src/Renderer/Rich/MethodDefinitionPlugin.php +++ b/src/Renderer/Rich/MethodDefinitionPlugin.php @@ -39,7 +39,7 @@ public function renderTab(Representation $r): ?string return null; } - if (isset($r->contents)) { + if (\is_string($r->contents)) { $docstring = []; foreach (\explode("\n", $r->contents) as $line) { $docstring[] = \trim($line); diff --git a/src/Renderer/Rich/SimpleXMLElementPlugin.php b/src/Renderer/Rich/SimpleXMLElementPlugin.php index 87d987079..c4dec62f6 100644 --- a/src/Renderer/Rich/SimpleXMLElementPlugin.php +++ b/src/Renderer/Rich/SimpleXMLElementPlugin.php @@ -39,6 +39,7 @@ public function renderValue(Value $o): ?string return null; } + /** @psalm-suppress RiskyTruthyFalsyComparison */ if (!$o->isStringValue() || !empty($o->getRepresentation('attributes')->contents)) { return null; } diff --git a/src/Renderer/Rich/TablePlugin.php b/src/Renderer/Rich/TablePlugin.php index 80fdd10f1..653342aa1 100644 --- a/src/Renderer/Rich/TablePlugin.php +++ b/src/Renderer/Rich/TablePlugin.php @@ -35,8 +35,12 @@ class TablePlugin extends AbstractPlugin implements TabPluginInterface { public static $respect_str_length = true; - public function renderTab(Representation $r): string + public function renderTab(Representation $r): ?string { + if (!\is_array($r->contents)) { + return null; + } + $out = '
';
 
         $firstrow = \reset($r->contents);
@@ -51,6 +55,7 @@ public function renderTab(Representation $r): string
 
         $out .= '';
 
+        /** $psalm-var \Kint\Zval\Value[] $r->contents */
         foreach ($r->contents as $row) {
             $out .= '
'; if (null !== ($s = $row->getName())) { diff --git a/src/Renderer/Rich/TimestampPlugin.php b/src/Renderer/Rich/TimestampPlugin.php index 43abfb60e..226db2b91 100644 --- a/src/Renderer/Rich/TimestampPlugin.php +++ b/src/Renderer/Rich/TimestampPlugin.php @@ -35,7 +35,7 @@ class TimestampPlugin extends AbstractPlugin implements TabPluginInterface { public function renderTab(Representation $r): ?string { - if ($dt = DateTime::createFromFormat('U', (string) $r->contents)) { + if (\is_scalar($r->contents) && ($dt = DateTime::createFromFormat('U', (string) $r->contents))) { return '
'.$dt->setTimeZone(new DateTimeZone('UTC'))->format('Y-m-d H:i:s T').'
'; } diff --git a/src/Renderer/RichRenderer.php b/src/Renderer/RichRenderer.php index b3d86ea1d..fa2cda7b9 100644 --- a/src/Renderer/RichRenderer.php +++ b/src/Renderer/RichRenderer.php @@ -269,7 +269,7 @@ public function renderHeaderWrapper(Value $o, bool $has_children, string $conten $out .= '>'; - if (self::$access_paths && $o->depth > 0 && ($ap = $o->getAccessPath())) { + if (self::$access_paths && $o->depth > 0 && null !== ($ap = $o->getAccessPath())) { $out .= ''; } @@ -304,7 +304,7 @@ public function renderHeader(Value $o): string if (null !== ($s = $o->getName())) { $output .= ''.$this->escape($s).' '; - if ($s = $o->getOperator()) { + if (null !== ($s = $o->getOperator())) { $output .= $this->escape($s, 'ASCII').' '; } } diff --git a/src/Utils.php b/src/Utils.php index 545709586..2f73beb8c 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -52,6 +52,8 @@ private function __construct() * @param int $value Amount of bytes * * @return array Human readable value and unit + * + * @psalm-return array{value: float, unit: 'B'|'KB'|'MB'|'GB'|'TB'} */ public static function getHumanReadableBytes(int $value): array { diff --git a/src/Zval/BlobValue.php b/src/Zval/BlobValue.php index 026c14378..32f267d18 100644 --- a/src/Zval/BlobValue.php +++ b/src/Zval/BlobValue.php @@ -130,7 +130,7 @@ public static function strlen(string $string, $encoding = false): int $encoding = self::detectEncoding($string); } - if ($encoding && 'ASCII' !== $encoding) { + if (false !== $encoding && 'ASCII' !== $encoding) { return \mb_strlen($string, $encoding); } } @@ -148,7 +148,7 @@ public static function substr(string $string, int $start, ?int $length = null, $ $encoding = self::detectEncoding($string); } - if ($encoding && 'ASCII' !== $encoding) { + if (false !== $encoding && 'ASCII' !== $encoding) { return \mb_substr($string, $start, $length, $encoding); } } @@ -167,7 +167,8 @@ public static function substr(string $string, int $start, ?int $length = null, $ public static function detectEncoding(string $string) { if (\function_exists('mb_detect_encoding')) { - if ($ret = \mb_detect_encoding($string, self::$char_encodings, true)) { + $ret = \mb_detect_encoding($string, self::$char_encodings, true); + if (false !== $ret) { return $ret; } } diff --git a/src/Zval/MethodValue.php b/src/Zval/MethodValue.php index 55c320981..e3e0dd10a 100644 --- a/src/Zval/MethodValue.php +++ b/src/Zval/MethodValue.php @@ -58,7 +58,8 @@ public function __construct(ReflectionFunctionAbstract $method) $this->startline = $method->getStartLine(); $this->endline = $method->getEndLine(); $this->internal = $method->isInternal(); - $this->docstring = $method->getDocComment() ?: null; + $ds = $method->getDocComment(); + $this->docstring = false === $ds ? null : $ds; $this->return_reference = $method->returnsReference(); foreach ($method->getParameters() as $param) { @@ -149,7 +150,7 @@ public function getValueShort(): ?string $ds = $this->value->getDocstringWithoutComments(); - if (!$ds) { + if (null === $ds) { return null; } diff --git a/src/Zval/ParameterValue.php b/src/Zval/ParameterValue.php index fa9d05ef5..a30f3753a 100644 --- a/src/Zval/ParameterValue.php +++ b/src/Zval/ParameterValue.php @@ -41,9 +41,7 @@ public function __construct(ReflectionParameter $param) { parent::__construct(); - if ($type = $param->getType()) { - $this->type_hint = Utils::getTypeString($type); - } + $this->type_hint = ($type = $param->getType()) ? Utils::getTypeString($type) : null; $this->reference = $param->isPassedByReference(); $this->name = $param->getName(); @@ -73,9 +71,12 @@ public function __construct(ReflectionParameter $param) $this->default = \gettype($default); break; } + } else { + $this->default = null; } } + /** @psalm-return ?truthy-string */ public function getType(): ?string { return $this->type_hint; @@ -86,6 +87,7 @@ public function getName(): string return '$'.$this->name; } + /** @psalm-return ?truthy-string */ public function getDefault(): ?string { return $this->default; diff --git a/src/Zval/Representation/ColorRepresentation.php b/src/Zval/Representation/ColorRepresentation.php index 806a80066..80e419695 100644 --- a/src/Zval/Representation/ColorRepresentation.php +++ b/src/Zval/Representation/ColorRepresentation.php @@ -41,6 +41,7 @@ class ColorRepresentation extends Representation public const COLOR_HEX_4 = 8; public const COLOR_HEX_8 = 9; + /** @psalm-var array */ public static $color_map = [ 'aliceblue' => 'f0f8ff', 'antiquewhite' => 'faebd7', @@ -211,6 +212,11 @@ public function __construct(string $value) $this->setValues($value); } + /** + * @psalm-param ?positive-int $variant + * + * @psalm-return ?truthy-string + */ public function getColor(?int $variant = null): ?string { if (!$variant) { @@ -225,6 +231,7 @@ public function getColor(?int $variant = null): ?string return \array_search($hex, self::$color_map, true) ?: \array_search($hex_alpha, self::$color_map, true) ?: null; case self::COLOR_HEX_3: if (0 === $this->r % 0x11 && 0 === $this->g % 0x11 && 0 === $this->b % 0x11) { + /** @psalm-var truthy-string */ return \sprintf( '#%1X%1X%1X', \round($this->r / 0x11), @@ -235,28 +242,36 @@ public function getColor(?int $variant = null): ?string return null; case self::COLOR_HEX_6: + /** @psalm-var truthy-string */ return \sprintf('#%02X%02X%02X', $this->r, $this->g, $this->b); case self::COLOR_RGB: if (1.0 === $this->a) { + /** @psalm-var truthy-string */ return \sprintf('rgb(%d, %d, %d)', $this->r, $this->g, $this->b); } + /** @psalm-var truthy-string */ return \sprintf('rgb(%d, %d, %d, %s)', $this->r, $this->g, $this->b, \round($this->a, 4)); case self::COLOR_RGBA: + /** @psalm-var truthy-string */ return \sprintf('rgba(%d, %d, %d, %s)', $this->r, $this->g, $this->b, \round($this->a, 4)); case self::COLOR_HSL: $val = self::rgbToHsl($this->r, $this->g, $this->b); if (1.0 === $this->a) { + /** @psalm-var truthy-string */ return \vsprintf('hsl(%d, %d%%, %d%%)', $val); } + /** @psalm-var truthy-string */ return \sprintf('hsl(%d, %d%%, %d%%, %s)', $val[0], $val[1], $val[2], \round($this->a, 4)); case self::COLOR_HSLA: $val = self::rgbToHsl($this->r, $this->g, $this->b); + /** @psalm-var truthy-string */ return \sprintf('hsla(%d, %d%%, %d%%, %s)', $val[0], $val[1], $val[2], \round($this->a, 4)); case self::COLOR_HEX_4: if (0 === $this->r % 0x11 && 0 === $this->g % 0x11 && 0 === $this->b % 0x11 && 0 === ((int) ($this->a * 255)) % 0x11) { + /** @psalm-var truthy-string */ return \sprintf( '#%1X%1X%1X%1X', \round($this->r / 0x11), @@ -269,6 +284,7 @@ public function getColor(?int $variant = null): ?string return null; case self::COLOR_HEX_8: + /** @psalm-var truthy-string */ return \sprintf('#%02X%02X%02X%02X', $this->r, $this->g, $this->b, \round($this->a * 0xFF)); } @@ -332,6 +348,7 @@ protected function setValues(string $value): void } } + /** @psalm-return ?positive-int */ protected function setValuesFromHex(string $hex): ?int { if (!\ctype_xdigit($hex)) { @@ -378,6 +395,7 @@ protected function setValuesFromHex(string $hex): ?int return $variant; } + /** @psalm-return ?positive-int */ protected function setValuesFromFunction(string $value): ?int { if (!\preg_match('/^((?:rgb|hsl)a?)\\s*\\(([0-9\\.%,\\s\\/\\-]+)\\)$/i', $value, $match)) { diff --git a/src/Zval/Representation/MethodDefinitionRepresentation.php b/src/Zval/Representation/MethodDefinitionRepresentation.php index 6c1ca38bb..bcc5499d7 100644 --- a/src/Zval/Representation/MethodDefinitionRepresentation.php +++ b/src/Zval/Representation/MethodDefinitionRepresentation.php @@ -64,7 +64,7 @@ public function __construct(?string $file, ?int $line, ?string $class, ?string $ */ public function getDocstringWithoutComments() { - if (!$this->contents) { + if (!\is_string($this->contents) || '' === $this->contents) { return null; } diff --git a/src/Zval/Representation/Representation.php b/src/Zval/Representation/Representation.php index c4680c3d1..b47a0ef47 100644 --- a/src/Zval/Representation/Representation.php +++ b/src/Zval/Representation/Representation.php @@ -32,6 +32,8 @@ class Representation public $label; public $implicit_label = false; public $hints = []; + + /** @psalm-var null|scalar|\Kint\Zval\Value|\Kint\Zval\Value[] */ public $contents = []; protected $name; diff --git a/src/Zval/Representation/SplFileInfoRepresentation.php b/src/Zval/Representation/SplFileInfoRepresentation.php index dad9d04cd..b09aea5fa 100644 --- a/src/Zval/Representation/SplFileInfoRepresentation.php +++ b/src/Zval/Representation/SplFileInfoRepresentation.php @@ -39,8 +39,11 @@ class SplFileInfoRepresentation extends Representation public $realpath = null; public $linktarget = null; public $size = null; + /** @var bool */ public $is_dir = false; + /** @var bool */ public $is_file = false; + /** @var bool */ public $is_link = false; public $owner = null; public $group = null; @@ -72,7 +75,8 @@ public function __construct(SplFileInfo $fileInfo) $this->is_link = $fileInfo->isLink(); if ($this->is_link) { - $this->linktarget = $fileInfo->getLinkTarget(); + $lt = $fileInfo->getLinkTarget(); + $this->linktarget = false === $lt ? null : $lt; } } catch (RuntimeException $e) { if (false === \strpos($e->getMessage(), ' open_basedir ')) { @@ -150,7 +154,7 @@ public function __construct(SplFileInfo $fileInfo) $this->contents = \implode($this->flags).' '.$this->owner.' '.$this->group; $this->contents .= ' '.$this->getSize().' '.$this->getMTime().' '; - if ($this->is_link && $this->linktarget) { + if ($this->is_link && null !== $this->linktarget) { $this->contents .= $this->path.' -> '.$this->linktarget; } elseif (null !== $this->realpath && \strlen($this->realpath) < \strlen($this->path)) { $this->contents .= $this->realpath; @@ -168,6 +172,7 @@ public function getLabel(): string return $this->typename; } + /** @psalm-return ?truthy-string */ public function getSize(): ?string { if ($this->size) { diff --git a/src/Zval/TraceFrameValue.php b/src/Zval/TraceFrameValue.php index bee073bb7..70937789b 100644 --- a/src/Zval/TraceFrameValue.php +++ b/src/Zval/TraceFrameValue.php @@ -58,10 +58,10 @@ public function __construct(Value $base, array $raw_frame) 'args' => null, ]; - if ($this->trace['class'] && \method_exists($this->trace['class'], $this->trace['function'])) { + if (null !== $this->trace['class'] && \method_exists($this->trace['class'], $this->trace['function'])) { $func = new ReflectionMethod($this->trace['class'], $this->trace['function']); $this->trace['function'] = new MethodValue($func); - } elseif (!$this->trace['class'] && \function_exists($this->trace['function'])) { + } elseif (null === $this->trace['class'] && \function_exists($this->trace['function'])) { $func = new ReflectionFunction($this->trace['function']); $this->trace['function'] = new MethodValue($func); } @@ -91,16 +91,16 @@ public function __construct(Value $base, array $raw_frame) $this->addRepresentation(new SourceRepresentation($this->trace['file'], $this->trace['line'])); } - if ($this->trace['args']) { + if (null !== $this->trace['args']) { $args = new Representation('Arguments'); $args->contents = $this->trace['args']; $this->addRepresentation($args); } - if ($this->trace['object']) { + if (null !== $this->trace['object']) { $callee = new Representation('object'); $callee->label = 'Callee object ['.$this->trace['object']->classname.']'; - $callee->contents[] = $this->trace['object']; + $callee->contents = [$this->trace['object']]; $this->addRepresentation($callee); } } diff --git a/src/Zval/Value.php b/src/Zval/Value.php index 37885d97e..4e3bf2279 100644 --- a/src/Zval/Value.php +++ b/src/Zval/Value.php @@ -56,6 +56,7 @@ class Value public $hints = []; public $value; + /** @var Representation[] */ protected $representations = []; public function __construct() @@ -108,6 +109,7 @@ public function getRepresentation(string $name): ?Representation return $this->representations[$name] ?? null; } + /** @psalm-return Representation[] */ public function getRepresentations(): array { return $this->representations; @@ -169,6 +171,7 @@ public function getName(): ?string return null; } + /** @psalm-return ?truthy-string */ public function getOperator(): ?string { switch ($this->operator) {