Skip to content

Commit

Permalink
Reduce phpstan-bugs error count
Browse files Browse the repository at this point in the history
these are all caused by the same bug phpstan/phpstan#10924
  • Loading branch information
dktapps committed Nov 16, 2024
1 parent e1f6aa9 commit 5537e9b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
17 changes: 14 additions & 3 deletions src/timings/TimingsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
27 changes: 1 addition & 26 deletions tests/phpstan/configs/phpstan-bugs.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5537e9b

Please sign in to comment.