GithubHelp home page GithubHelp logo

Comments (12)

johnbillion avatar johnbillion commented on July 3, 2024 1

If there's a @param <something>|array and it's documented with an array hash notation then the @phpstan-param tag gets added with the array shape. So yes, a union type gets reduced to an array shape.

from wordpress-stubs.

szepeviktor avatar szepeviktor commented on July 3, 2024

Hello Victor!
Thank you for your report.

It boils down to your custom HTML attribute.
Please consider adding a stubs file to your PHPStan config that fits your usage of wp_get_attachment_image as this package is automatically generated.
I suggest you to add data-secondary to the list of allowed string.

from wordpress-stubs.

szepeviktor avatar szepeviktor commented on July 3, 2024

I see!!!
WP core has @param string|array $attr
we interpret it as @phpstan-param array{...

BTW I think this function cannot handle boolean attributes: $html .= " $name=" . '"' . $value . '"';
@UVLabs What is your actual HTML output?

from wordpress-stubs.

szepeviktor avatar szepeviktor commented on July 3, 2024

@johnbillion Could it be that we reduce UnionType to a simple array?

from wordpress-stubs.

UVLabs avatar UVLabs commented on July 3, 2024

BTW I think this function cannot handle boolean attributes: $html .= " $name=" . '"' . $value . '"';
@UVLabs What is your actual HTML output?

@szepeviktor I'm not sure what you mean here? The function returns the image HTML

I've ignored the error for now but it looks like a false positive

from wordpress-stubs.

szepeviktor avatar szepeviktor commented on July 3, 2024

I'm not sure what you mean here?

What is your current HTML code that is printed by wp_get_attachment_image.
E.g. <img ... >

from wordpress-stubs.

UVLabs avatar UVLabs commented on July 3, 2024

I'm not sure what you mean here?

What is your current HTML code that is printed by wp_get_attachment_image. E.g. <img ... >

@szepeviktor :

image

from wordpress-stubs.

szepeviktor avatar szepeviktor commented on July 3, 2024

Thank you!

Now it is sure that this function does not support "boolean HTML attributes".
It should be <img ... data-secondary />

from wordpress-stubs.

UVLabs avatar UVLabs commented on July 3, 2024

@szepeviktor That photo was from a dump of the return, but I can see that when this renders on the page (Google Chrome) its as expected:

image

I changed the code to instead use an array:

wp_get_attachment_image( $gallery_attachment_ids[0], $image_size, false, array( 'class' => 'secondary-img' ) ); and PHP stan no longer throws the error

from wordpress-stubs.

UVLabs avatar UVLabs commented on July 3, 2024

@szepeviktor I'm still not sure at this point if this was truly a false positive, the documentation is a little unclear for that particular parameter but if a string is allowed as per the wp.org doc, then there shouldn't have been error

from wordpress-stubs.

johnbillion avatar johnbillion commented on July 3, 2024

The primary reason for this is parameters that accept string|array where the string is a URL query string which no sane person should be using to pass arguments.

from wordpress-stubs.

szepeviktor avatar szepeviktor commented on July 3, 2024

I changed the code to instead use an array

@UVLabs Thank you for using an array!

from wordpress-stubs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.