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

Infer more DOMDocument types when loaded #11120

Open
jnvsor opened this issue Oct 11, 2024 · 1 comment
Open

Infer more DOMDocument types when loaded #11120

jnvsor opened this issue Oct 11, 2024 · 1 comment

Comments

@jnvsor
Copy link
Contributor

jnvsor commented Oct 11, 2024

https://psalm.dev/r/01eac6a01b

When DOMDocument methods load, loadXML, loadHTML, loadHTMLFile return true DOMDocument must have at least one node.

Copy link

I found these snippets:

https://psalm.dev/r/01eac6a01b
<?php

function test(string $file): DOMNode {
    $xml = new DOMDocument();
    $check = $xml->loadXML($file, LIBXML_NOWARNING | LIBXML_NOERROR);

    if (false === $check) {
        throw new Exception();
    }
    
    return $xml->firstChild;
}
Psalm output (using commit 03ee02c):

ERROR: NullableReturnStatement - 11:12 - The declared return type 'DOMNode' for test is not nullable, but the function returns 'DOMNode|null'

ERROR: InvalidNullableReturnType - 3:30 - The declared return type 'DOMNode' for test is not nullable, but 'DOMNode|null' contains null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant