getContext(); $out = \call_user_func([$this, 'xmlTo'.self::$parse_method], $var, $c); if (null === $out) { return $v; } $out->flags |= AbstractValue::FLAG_GENERATED; $v->addRepresentation(new ValueRepresentation('XML', $out), 0); return $v; } /** @psalm-suppress PossiblyUnusedMethod */ protected function xmlToSimpleXML(string $var, ContextInterface $c): ?AbstractValue { $errors = \libxml_use_internal_errors(true); try { $xml = \simplexml_load_string($var); if (!(bool) $xml) { throw new InvalidArgumentException('Bad XML parse in XmlPlugin::xmlToSimpleXML'); } } catch (Throwable $t) { return null; } finally { \libxml_use_internal_errors($errors); \libxml_clear_errors(); } $base = new BaseContext($xml->getName()); $base->depth = $c->getDepth() + 1; if (null !== ($ap = $c->getAccessPath())) { $base->access_path = 'simplexml_load_string('.$ap.')'; } return $this->getParser()->parse($xml, $base); } /** * Get the DOMDocument info. * * 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 { try { $xml = new DOMDocument(); $check = $xml->loadXML($var, LIBXML_NOWARNING | LIBXML_NOERROR); if (false === $check) { throw new InvalidArgumentException('Bad XML parse in XmlPlugin::xmlToDOMDocument'); } } catch (Throwable $t) { return null; } $xml = $xml->firstChild; /** * @psalm-var DOMNode $xml * Psalm bug #11120 */ $base = new BaseContext($xml->nodeName); $base->depth = $c->getDepth() + 1; if (null !== ($ap = $c->getAccessPath())) { $base->access_path = '(function($s){$x = new \\DomDocument(); $x->loadXML($s); return $x;})('.$ap.')->firstChild'; } return $this->getParser()->parse($xml, $base); } /** @psalm-suppress PossiblyUnusedMethod */ protected function xmlToXMLDocument(string $var, ContextInterface $c): ?AbstractValue { if (!KINT_PHP84) { return null; // @codeCoverageIgnore } try { $xml = XMLDocument::createFromString($var, LIBXML_NOWARNING | LIBXML_NOERROR); } catch (DOMException $e) { return null; } $xml = $xml->firstChild; /** * @psalm-var Node $xml * Psalm bug #11120 */ $base = new BaseContext($xml->nodeName); $base->depth = $c->getDepth() + 1; if (null !== ($ap = $c->getAccessPath())) { $base->access_path = '\\Dom\\XMLDocument::createFromString('.$ap.')->firstChild'; } return $this->getParser()->parse($xml, $base); } }