Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOMNode childNodes expecting a DOMNodeList of DomNode instead of DOMNode #8576

Closed
cristianobaptista opened this issue Oct 13, 2022 · 4 comments
Labels
bug easy problems Issues that can be fixed without background knowledge of Psalm Help wanted internal stubs/callmap

Comments

@cristianobaptista
Copy link

If you loop through each of the items in a childNodes list as DOMNode, like in the following code:

$dom = new \DOMDocument();
$node = new \DOMNode();

echo implode('', array_map(
    fn (\DOMNode $node): string => trim($dom->saveHTML($node)),
    iterator_to_array($node->childNodes)
));

Psalm will return the following error:

InvalidClass - Class, interface or enum DomNode has wrong casing (see https://psalm.dev/007)

This is happening on v4.8.1 due to wrong casing on the PropertiesMap for domnode that should be DOMNodeList<DOMNode> instead of DomNodeList<DomNode>.

This is the commit that introduced the bug: #5403

I also tried to replicate the issue using psalm.dev but was unable to: https://psalm.dev/r/0957fc5f47
Maybe it depends on the case sensitivity of the system running psalm.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/0957fc5f47
<?php 

$html = implode('', [
    '<div>',
    '<ul>',
    '<li>ITEM 1</li>',
    '<li>ITEM 2</li>',
    '</ul>',
    '</div>',
]);
$dom = new \DOMDocument();
$dom->loadHtml($html);

$list = $dom->getElementsByTagName('ul')->item(0);

echo implode('', array_map(
    fn (\DOMNode $node): string => trim($dom->saveHTML($node)),
    iterator_to_array($list->childNodes)
));
Psalm output (using commit bb9aabe):

No issues!

@orklah
Copy link
Collaborator

orklah commented Oct 13, 2022

Seems legit :)

Can you propose a PR? 🙂

@cristianobaptista
Copy link
Author

Sure thing, here it is: #8577

@weirdan
Copy link
Collaborator

weirdan commented Nov 10, 2022

Fixed in #8577

@weirdan weirdan closed this as completed Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug easy problems Issues that can be fixed without background knowledge of Psalm Help wanted internal stubs/callmap
Projects
None yet
Development

No branches or pull requests

3 participants