Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"wp-coding-standards/wpcs": "~3.3.0",
"phpcompatibility/phpcompatibility-wp": "~2.1.3",
"phpstan/phpstan": "2.2.2",
"phpstan/phpstan-phpunit": "2.0.16",
"yoast/phpunit-polyfills": "^1.1.0"
},
"config": {
Expand Down
6 changes: 6 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ includes:
# The base configuration file for using PHPStan with the WordPress core codebase.
- tests/phpstan/base.neon

# Type-specifying extension so PHPUnit assertions (e.g. assertArrayHasKey(),
# assertInstanceOf(), assertNotNull()) narrow types in the analysis. Only the
# extension is included, not phpstan-phpunit's rules.neon, to avoid introducing
# new strict rules.
- vendor/phpstan/phpstan-phpunit/extension.neon

# The baseline file includes preexisting errors in the codebase that should be ignored.
# https://phpstan.org/user-guide/baseline
- tests/phpstan/baseline.php
Expand Down
9 changes: 9 additions & 0 deletions src/wp-admin/includes/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,9 @@ function validate_file_to_edit( $file, $allowed_files = array() ) {
* @type string $url URL of the newly-uploaded file.
* @type string $type Mime type of the newly-uploaded file.
* }
*
* @phpstan-return array{ file: non-empty-string, url: non-empty-string, type: non-empty-string }
* |array{ error: non-empty-string }
*/
function _wp_handle_upload( &$file, $overrides, $time, $action ) {
// The default error handler.
Expand Down Expand Up @@ -1094,6 +1097,9 @@ function wp_handle_upload_error( &$file, $message ) {
* See _wp_handle_upload() for accepted values.
* @param string|null $time Optional. Time formatted in 'yyyy/mm'. Default null.
* @return array See _wp_handle_upload() for return value.
*
* @phpstan-return array{ file: non-empty-string, url: non-empty-string, type: non-empty-string }
* |array{ error: non-empty-string }
*/
function wp_handle_upload( &$file, $overrides = false, $time = null ) {
/*
Expand Down Expand Up @@ -1121,6 +1127,9 @@ function wp_handle_upload( &$file, $overrides = false, $time = null ) {
* See _wp_handle_upload() for accepted values.
* @param string|null $time Optional. Time formatted in 'yyyy/mm'. Default null.
* @return array See _wp_handle_upload() for return value.
*
* @phpstan-return array{ file: non-empty-string, url: non-empty-string, type: non-empty-string }
* |array{ error: non-empty-string }
*/
function wp_handle_sideload( &$file, $overrides = false, $time = null ) {
/*
Expand Down
16 changes: 16 additions & 0 deletions src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,14 @@ function win_is_writable( $path ) {
* @see wp_upload_dir()
*
* @return array See wp_upload_dir() for description.
* @phpstan-return array{
* path: non-empty-string,
* url: non-empty-string,
* subdir: non-empty-string,
* basedir: non-empty-string,
* baseurl: non-empty-string,
* }
* |array{ error: non-empty-string }
*/
function wp_get_upload_dir() {
return wp_upload_dir( null, false );
Expand Down Expand Up @@ -2382,6 +2390,14 @@ function wp_get_upload_dir() {
* @type string $baseurl URL path without subdir.
* @type string|false $error False or error message.
* }
* @phpstan-return array{
* path: non-empty-string,
* url: non-empty-string,
* subdir: non-empty-string,
* basedir: non-empty-string,
* baseurl: non-empty-string,
* }
* |array{ error: non-empty-string }
*/
function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = false ) {
static $cache = array(), $tested_paths = array();
Expand Down
33 changes: 33 additions & 0 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -6888,6 +6888,39 @@ function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) {
* @type array $image_meta Image metadata.
* @type int $filesize File size of the attachment.
* }
*
* @phpstan-return array{
* width?: int<1, max>,
* height?: int<1, max>,
* file?: non-empty-string,
* filesize?: int<0, max>,
* original_image?: non-empty-string,
* source_image?: non-empty-string,
* sizes?: array<non-empty-string, array{
* file: non-empty-string,
* width: int<1, max>,
* height: int<1, max>,
* 'mime-type': non-empty-string,
* filesize?: int<0, max>,
* ...
* }>,
* image_meta?: array{
* aperture: numeric-string|int,
* credit: string,
* camera: string,
* caption: string,
* created_timestamp: numeric-string|int,
* copyright: string,
* focal_length: numeric-string|int,
* iso: numeric-string|int,
* shutter_speed: numeric-string|int,
* title: string,
* orientation: numeric-string|int,
* keywords: list<string>,
* alt: string,
* },
* ...
* }|false
*/
function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
$attachment_id = (int) $attachment_id;
Expand Down
18 changes: 18 additions & 0 deletions src/wp-includes/rest-api/class-wp-rest-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,15 @@ public function set_body_params( $params ) {
* @since 4.4.0
*
* @return array Parameter map of key to value.
*
* @phpstan-return array<string, array{
* name: non-empty-string,
* type: non-empty-string,
* size: non-negative-int,
* tmp_name: non-empty-string,
* error: int<0, 8>,
* full_path?: non-empty-string,
* }>
*/
public function get_file_params() {
return $this->params['FILES'];
Expand All @@ -601,6 +610,15 @@ public function get_file_params() {
* @since 4.4.0
*
* @param array $params Parameter map of key to value.
*
* @phpstan-param array<string, array{
* name: non-empty-string,
* type: non-empty-string,
* size: non-negative-int,
* tmp_name: non-empty-string,
* error: int<0, 8>,
* full_path?: non-empty-string,
* }> $params
*/
public function set_file_params( $params ) {
$this->params['FILES'] = $params;
Expand Down
Loading