Comments (5)
core-stubs.php
<?php
function apple(): void
{
echo 'Apple is a fruit';
}
app.php
<?php
if (! function_exists('apple')) :
function apple(): void
{
echo 'Apple is a juicy fruit';
}
endif;
phpstan analyse -a core-stubs.php -l max app.php
[OK] No errors
from wordpress-stubs.
Thank you again for your suggestion.
is wrapped in an
if ( ! function_exists )
block. The stubs for these should ideally be treated the same
Just wrap your functions overriding core functions in function_exists
.
from wordpress-stubs.
While that was one option I considered, I ruled this out as my implementation is maintained by me I'd rather mine be analysed in my project by PHPStan than use the stub implementation.
From the looks of it, this repo uses another one of @GiacoCorsiglia to generate the stubs and I'd guess this underlying library doesn't account for the functions that wp-core if
wraps. So if they're active or around then maybe I could help fix that upstream.
However per your other comments though it seems they may not be as active to accept the PR?
from wordpress-stubs.
I'd rather mine be analysed in my project by PHPStan than use the stub implementation.
Actually PHPStan does analyze your code.
Changing app.php to
<?php
if (! function_exists('apple')) :
function apple(): void
{
echo 'Apple is a juicy fruit';
return $horribleError;
}
endif;
produces 2 errors
------ --------------------------------------------------------------------------------------
Line app.php
------ --------------------------------------------------------------------------------------
8 Function apple() with return type void returns mixed but should not return anything.
8 Undefined variable: $horribleError
------ --------------------------------------------------------------------------------------
from wordpress-stubs.
Sorry - I may be a bit confused about PHPStan's inner workings, or poorly explained my thought/concern.
My thought was that the areas of my code/wp-core that utilize said function would analyze it differently if it associated it with the stub vs with my implementation.
However now that I write that out I realize that's an assumption I've made about how PHPStan connects/associates different areas of code during analysis.
from wordpress-stubs.
Related Issues (20)
- Include `wp-includes/compat.php` HOT 10
- `wp_is_development_mode()` is missing from the stubs HOT 5
- wp_insert_attachment doesn't show WP_Error as possible return value HOT 5
- 6.4 new see tag HOT 9
- Tests for functionMap.php HOT 1
- Widget::widget() has never return type HOT 1
- stubs for wpdb::get_row() and wpdb::get_results() are wrong HOT 10
- 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.