Skip to content

Commit b540a1f

Browse files
committed
Improve and fix window event listener
1 parent 3c8e835 commit b540a1f

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

src/WeakClosure.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
* @internal Use the {@see WeakClosure::create()} instead
5252
*
5353
* @param TThis $reference The object bound to the original closure
54-
* @param \Closure $callback The original closure to wrap
5554
*/
5655
private function __construct(object $reference, \Closure $callback)
5756
{
@@ -64,21 +63,24 @@ private function __construct(object $reference, \Closure $callback)
6463
* Creates a {@see WeakClosure} from a callable, or returns the callable
6564
* unchanged if it is not bound to an object
6665
*
67-
* @param callable $callback The callable to potentially wrap
68-
* @return callable Returns a {@see WeakClosure} instance if the callable
69-
* is bound to an object, otherwise returns the original callable
70-
* @throws \ReflectionException in case of internal error occurs
66+
* @template TArgClosure of \Closure
67+
*
68+
* @param TArgClosure $callback The callable to potentially wrap
69+
* @return TArgClosure Returns a {@see \Closure} instance with weak
70+
* reference to `$this`
71+
*
72+
* @noinspection PhpDocMissingThrowsInspection An exception never throws
7173
*/
72-
public static function create(callable $callback): callable
74+
public static function create(\Closure $callback): \Closure
7375
{
74-
$reference = new \ReflectionFunction($closure = $callback(...))
76+
$reference = new \ReflectionFunction($callback)
7577
->getClosureThis();
7678

7779
if ($reference === null) {
78-
return $closure;
80+
return $callback;
7981
}
8082

81-
return new self($reference, $closure);
83+
return (new self($reference, $callback))(...);
8284
}
8385

8486
/**

0 commit comments

Comments
 (0)