Comments (12)
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.
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.
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.
@johnbillion Could it be that we reduce UnionType to a simple array?
from wordpress-stubs.
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.
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.
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.
Thank you!
Now it is sure that this function does not support "boolean HTML attributes".
It should be <img ... data-secondary />
from wordpress-stubs.
@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:
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.
@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.
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.
I changed the code to instead use an array
@UVLabs Thank you for using an array!
from wordpress-stubs.
Related Issues (20)
- Include `wp-includes/compat.php` HOT 10
- `wp_is_development_mode()` is missing from the stubs HOT 5
- Expand `$args` array parameters that are described in other functions HOT 1
- Handle `@type` tags without static keys HOT 2
- Create releases of tags HOT 3
- php deprication notices in 8.1 HOT 7
- False positive when slashing data for wp_insert_post() and wp_update_post() HOT 7
- PHPStan documentation of wp_update_post() seems to be too restrictive HOT 5
- Fix page link types HOT 2
- Incorrect stubs since >5.9.3 + mismatch between packagist.org and GitHub HOT 17
- DocblockTypeContradiction with get_settings_errors() HOT 4
- Does anyone know when Request v2 will be part of core? HOT 2
- Test with new nikic/php-parser HOT 2
- Why globals are not included? HOT 5
- Improve types for `WP_REST_Request` HOT 3
- Check if function exists in wordpress-stubs.php HOT 7
- WordPress 6.2 in WordPress any more HOT 7
- functionMap.php wrong HOT 4
- `WP_Filesystem_Base::dirlist` returns an array<array> HOT 6
- Ondลej says: It doesn't make sense to combine void with something else in a union type. HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wordpress-stubs.