Skip to content
Merged
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
3 changes: 3 additions & 0 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@
'WP_Block_List::offsetGet' => ['\WP_Block|null', 'offset' => 'int'],
'WP_Block_List::offsetSet' => ['void', 'offset' => 'int|null'],
'WP_Block_List::offsetUnset' => ['void', 'offset' => 'int'],
'WP_Dependencies::$groups' => [null, '@phpstan-var' => 'array<string, int|false>'],
'WP_Dependencies::get_etag' => ['non-falsy-string'],
'WP_Dependencies::query' => ["(\$handle is not non-empty-string ? false : (\$status is not TStatus ? false : (\$status is 'registered'|'scripts' ? _WP_Dependency|false : bool)))", '@phpstan-template TStatus' => "'registered'|'scripts'|'enqueued'|'queued'|'to_do'|'to_print'|'done'|'printed'"],
'WP_Filesystem_Base::dirlist' => [$filesystemDirlistReturnType],
'WP_Filesystem_Direct::dirlist' => [$filesystemDirlistReturnType],
'WP_Filesystem_FTPext::dirlist' => [$filesystemDirlistReturnType],
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ parameters:
-
path: tests/Faker.php
identifier: class.notFound
count: 13
count: 16
-
# PHPStan\Analyser\Analyser::analyse()
# PHPStan\Analyser\AnalyserResult::getErrors()
Expand Down
3 changes: 3 additions & 0 deletions tests/Faker.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@
* @method static \stdClass stdClass()
* @method static \WP_Block wpBlock()
* @method static \WP_Comment wpComment()
* @method static \WP_Dependencies wpDependencies()
* @method static \WP_Error wpError()
* @method static \WP_Post wpPost()
* @method static \WP_Query wpQuery()
* @method static \WP_REST_Request wpRestRequest()
* @method static \WP_REST_Response wpRestResponse()
* @method static \WP_Scripts wpScripts()
* @method static \WP_Styles wpStyles()
* @method static \WP_Term wpTerm()
* @method static \WP_Theme wpTheme()
* @method static \WP_Translations wpTranslations()
Expand Down
1 change: 1 addition & 0 deletions tests/TypeInferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_create_nonce.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_cron.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_debug_backtrace_summary.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_dependencies.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_die.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_dropdown_languages.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_error_parameter.php');
Expand Down
3 changes: 3 additions & 0 deletions tests/data/Faker.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,14 @@
// WordPress
assertType('WP_Block', Faker::wpBlock());
assertType('WP_Comment', Faker::wpComment());
assertType('WP_Dependencies', Faker::wpDependencies());
assertType('WP_Error', Faker::wpError());
assertType('WP_Post', Faker::wpPost());
assertType('WP_Query', Faker::wpQuery());
assertType('WP_REST_Request', Faker::wpRestRequest());
assertType('WP_REST_Response', Faker::wpRestResponse());
assertType('WP_Scripts', Faker::wpScripts());
assertType('WP_Styles', Faker::wpStyles());
assertType('WP_Term', Faker::wpTerm());
assertType('WP_Theme', Faker::wpTheme());
assertType('WP_Translations', Faker::wpTranslations());
Expand Down
34 changes: 34 additions & 0 deletions tests/data/wp_dependencies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace PhpStubs\WordPress\Core\Tests;

use function PHPStan\Testing\assertType;

assertType('array<string, int|false>', Faker::wpDependencies()->groups);
assertType('array<string, int|false>', Faker::wpScripts()->groups);
assertType('array<string, int|false>', Faker::wpStyles()->groups);

assertType('non-falsy-string', Faker::wpDependencies()->get_etag(Faker::array(Faker::string())));
assertType('non-falsy-string', Faker::wpScripts()->get_etag(Faker::array(Faker::string())));
assertType('non-falsy-string', Faker::wpStyles()->get_etag(Faker::array(Faker::string())));

// Always false if $handle is not non-empty-string
assertType('false', Faker::wpDependencies()->query(null, Faker::string()));
assertType('false', Faker::wpDependencies()->query('', Faker::string()));
assertType('false', Faker::wpScripts()->query('', Faker::string()));
assertType('false', Faker::wpStyles()->query('', Faker::string()));

assertType('_WP_Dependency|false', Faker::wpDependencies()->query(Faker::nonEmptyString(), 'registered'));
assertType('_WP_Dependency|false', Faker::wpDependencies()->query(Faker::nonEmptyString(), 'scripts'));
assertType('bool', Faker::wpDependencies()->query(Faker::nonEmptyString(), 'enqueued'));
assertType('bool', Faker::wpDependencies()->query(Faker::nonEmptyString(), 'queued'));
assertType('bool', Faker::wpDependencies()->query(Faker::nonEmptyString(), 'to_do'));
assertType('bool', Faker::wpDependencies()->query(Faker::nonEmptyString(), 'to_print'));
assertType('bool', Faker::wpDependencies()->query(Faker::nonEmptyString(), 'done'));
assertType('bool', Faker::wpDependencies()->query(Faker::nonEmptyString(), 'printed'));
assertType('_WP_Dependency|false', Faker::wpScripts()->query(Faker::nonEmptyString(), 'registered'));
assertType('bool', Faker::wpScripts()->query(Faker::nonEmptyString(), 'enqueued'));
assertType('_WP_Dependency|false', Faker::wpStyles()->query(Faker::nonEmptyString(), 'registered'));
assertType('bool', Faker::wpStyles()->query(Faker::nonEmptyString(), 'enqueued'));
4 changes: 4 additions & 0 deletions wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -37438,6 +37438,7 @@ class WP_Dependencies
* @since 2.8.0
*
* @var (int|false)[]
* @phpstan-var array<string, int|false>
*/
public $groups = array();
/**
Expand Down Expand Up @@ -37617,6 +37618,8 @@ protected function recurse_deps($queue, $handle)
* @param string $handle Name of the item. Should be unique.
* @param string $status Optional. Status of the item to query. Default 'registered'.
* @return bool|_WP_Dependency Found, or object Item data.
* @phpstan-template TStatus 'registered'|'scripts'|'enqueued'|'queued'|'to_do'|'to_print'|'done'|'printed'
* @phpstan-return ($handle is not non-empty-string ? false : ($status is not TStatus ? false : ($status is 'registered'|'scripts' ? _WP_Dependency|false : bool)))
*/
public function query($handle, $status = 'registered')
{
Expand All @@ -37643,6 +37646,7 @@ public function set_group($handle, $recursion, $group)
*
* @param string[] $load Array of script or style handles to load.
* @return string Etag header.
* @phpstan-return non-falsy-string
*/
public function get_etag($load)
{
Expand Down