Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async task timings #6333

Merged
merged 17 commits into from
Dec 1, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Reduce phpstan-bugs error count
these are all caused by the same bug phpstan/phpstan#10924
dktapps committed Nov 16, 2024
commit 5537e9b208ece38900f36e0816fc586c92740101
17 changes: 14 additions & 3 deletions src/timings/TimingsHandler.php
Original file line number Diff line number Diff line change
@@ -50,20 +50,31 @@ class TimingsHandler{
/** @phpstan-var ObjectSet<\Closure() : list<CollectPromise>> */
private static ?ObjectSet $collectCallbacks = null;

/**
* @phpstan-template T of object
* @phpstan-param ?ObjectSet<T> $where
* @phpstan-param-out ObjectSet<T> $where
* @phpstan-return ObjectSet<T>
*/
private static function lazyGetSet(?ObjectSet &$where) : ObjectSet{
//workaround for phpstan bug - allows us to ignore 1 error instead of 6 without suppressing other errors
return $where ??= new ObjectSet();
}

/**
* @phpstan-return ObjectSet<\Closure(bool $enable) : void>
*/
public static function getToggleCallbacks() : ObjectSet{ return self::$toggleCallbacks ??= new ObjectSet(); }
public static function getToggleCallbacks() : ObjectSet{ return self::lazyGetSet(self::$toggleCallbacks); }

/**
* @phpstan-return ObjectSet<\Closure() : void>
*/
public static function getReloadCallbacks() : ObjectSet{ return self::$reloadCallbacks ??= new ObjectSet(); }
public static function getReloadCallbacks() : ObjectSet{ return self::lazyGetSet(self::$reloadCallbacks); }

/**
* @phpstan-return ObjectSet<\Closure() : list<CollectPromise>>
*/
public static function getCollectCallbacks() : ObjectSet{ return self::$collectCallbacks ??= new ObjectSet(); }
public static function getCollectCallbacks() : ObjectSet{ return self::lazyGetSet(self::$collectCallbacks); }

/**
* @return string[]
27 changes: 1 addition & 26 deletions tests/phpstan/configs/phpstan-bugs.neon
Original file line number Diff line number Diff line change
@@ -91,32 +91,7 @@ parameters:
path: ../../../src/plugin/PluginManager.php

-
message: "#^Method pocketmine\\\\timings\\\\TimingsHandler\\:\\:getCollectCallbacks\\(\\) should return pocketmine\\\\utils\\\\ObjectSet\\<Closure\\(\\)\\: array\\<int, pocketmine\\\\promise\\\\Promise\\<array\\<int, string\\>\\>\\>\\> but returns pocketmine\\\\utils\\\\ObjectSet\\<Closure\\(\\)\\: array\\<int, pocketmine\\\\promise\\\\Promise\\<array\\<int, string\\>\\>\\>\\>\\|pocketmine\\\\utils\\\\ObjectSet\\<object\\>\\.$#"
count: 1
path: ../../../src/timings/TimingsHandler.php

-
message: "#^Method pocketmine\\\\timings\\\\TimingsHandler\\:\\:getResetCallbacks\\(\\) should return pocketmine\\\\utils\\\\ObjectSet\\<Closure\\(\\)\\: void\\> but returns pocketmine\\\\utils\\\\ObjectSet\\<Closure\\(\\)\\: void\\>\\|pocketmine\\\\utils\\\\ObjectSet\\<object\\>\\.$#"
count: 1
path: ../../../src/timings/TimingsHandler.php

-
message: "#^Method pocketmine\\\\timings\\\\TimingsHandler\\:\\:getToggleCallbacks\\(\\) should return pocketmine\\\\utils\\\\ObjectSet\\<Closure\\(bool\\)\\: void\\> but returns pocketmine\\\\utils\\\\ObjectSet\\<Closure\\(bool\\)\\: void\\>\\|pocketmine\\\\utils\\\\ObjectSet\\<object\\>\\.$#"
count: 1
path: ../../../src/timings/TimingsHandler.php

-
message: "#^Static property pocketmine\\\\timings\\\\TimingsHandler\\:\\:\\$collectCallbacks \\(pocketmine\\\\utils\\\\ObjectSet\\<Closure\\(\\)\\: array\\<int, pocketmine\\\\promise\\\\Promise\\<array\\<int, string\\>\\>\\>\\>\\|null\\) does not accept pocketmine\\\\utils\\\\ObjectSet\\<Closure\\(\\)\\: array\\<int, pocketmine\\\\promise\\\\Promise\\<array\\<int, string\\>\\>\\>\\>\\|pocketmine\\\\utils\\\\ObjectSet\\<object\\>\\.$#"
count: 1
path: ../../../src/timings/TimingsHandler.php

-
message: "#^Static property pocketmine\\\\timings\\\\TimingsHandler\\:\\:\\$resetCallbacks \\(pocketmine\\\\utils\\\\ObjectSet\\<Closure\\(\\)\\: void\\>\\|null\\) does not accept pocketmine\\\\utils\\\\ObjectSet\\<Closure\\(\\)\\: void\\>\\|pocketmine\\\\utils\\\\ObjectSet\\<object\\>\\.$#"
count: 1
path: ../../../src/timings/TimingsHandler.php

-
message: "#^Static property pocketmine\\\\timings\\\\TimingsHandler\\:\\:\\$toggleCallbacks \\(pocketmine\\\\utils\\\\ObjectSet\\<Closure\\(bool\\)\\: void\\>\\|null\\) does not accept pocketmine\\\\utils\\\\ObjectSet\\<Closure\\(bool\\)\\: void\\>\\|pocketmine\\\\utils\\\\ObjectSet\\<object\\>\\.$#"
message: "#^Method pocketmine\\\\timings\\\\TimingsHandler\\:\\:lazyGetSet\\(\\) should return pocketmine\\\\utils\\\\ObjectSet\\<T of object\\> but returns pocketmine\\\\utils\\\\ObjectSet\\<object\\>\\.$#"
count: 1
path: ../../../src/timings/TimingsHandler.php