Skip to content
This repository was archived by the owner on Feb 13, 2022. It is now read-only.

Commit 714904f

Browse files
committed
Better type annotations
1 parent 05a4ffa commit 714904f

File tree

6 files changed

+26
-15
lines changed

6 files changed

+26
-15
lines changed

src/Functional/Functional.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Identity function.
1616
*
1717
* @template T
18-
* @return Closure(mixed): mixed
18+
* @return Closure(T): T
1919
*/
2020
function identity(): Closure
2121
{
@@ -34,7 +34,7 @@ static function ($value) {
3434
*
3535
* @template T
3636
* @param T $value
37-
* @return Closure(): mixed
37+
* @return Closure(): T
3838
*/
3939
function always($value): Closure
4040
{
@@ -107,14 +107,14 @@ static function ($left) use ($right) {
107107
*
108108
* @param callable(mixed): bool $cond
109109
*
110-
* @return Closure(callable): Closure(callable): Closure(mixed): mixed
110+
* @return Closure(callable(mixed):mixed):Closure(callable(mixed):mixed):Closure(mixed):mixed
111111
*/
112112
function if_else(callable $cond): Closure
113113
{
114114
return
115115
/**
116116
* @param callable(mixed): mixed $then
117-
* @return Closure(callable): Closure(mixed): mixed
117+
* @return Closure(callable(mixed):mixed):Closure(mixed):mixed
118118
*/
119119
static function (callable $then) use ($cond): Closure {
120120
return
@@ -156,7 +156,7 @@ static function ($value) use ($matches) {
156156
return null;
157157
}
158158

159-
/** @var array<callable> $match */
159+
/** @var array<callable(mixed):bool> $match */
160160
$match = $matches[0];
161161
$if_else = if_else($match[0])($match[1])(match(array_slice($matches, 1)));
162162

src/Http/Request.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
*/
2424
function raw(string $input = 'php://input'): string
2525
{
26-
return (string)file_get_contents($input);
26+
$contents = file_get_contents($input);
27+
return $contents === false ? '' : $contents;
2728
}
2829

2930
/**
@@ -359,8 +360,12 @@ function authorization_header($request = null): ?string
359360
if (Container\has(SWOOLE_HTTP_REQUEST)) {
360361
/** @var Request $request */
361362
$request = Container\get(SWOOLE_HTTP_REQUEST);
362-
/** @var string|null */
363-
return $request->header['authorization'] ?? null;
363+
/**
364+
* @psalm-suppress MissingPropertyType
365+
* @var array<string, string> $request_header
366+
*/
367+
$request_header = $request->header;
368+
return $request_header['authorization'] ?? null;
364369
}
365370

366371
if ($request instanceof ServerRequestInterface) {

src/Siler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/**
1111
* Get a value from an array checking if the key exists and returning a default value if not.
1212
*
13+
* @psalm-suppress LessSpecificReturnType
1314
* @template T
1415
* @param array<string, T>|null $array
1516
* @param string|null $key The key to be searched
@@ -42,7 +43,7 @@ function array_get(?array $array, ?string $key = null, $default = null, bool $ca
4243
*
4344
* @return Closure
4445
*
45-
* @return Closure(array=):(false|mixed|null)
46+
* @return Closure(string[]):(false|mixed|null)
4647
*/
4748
function require_fn(string $filename): Closure
4849
{

src/Stratigility/RequestHandlerDecorator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class RequestHandlerDecorator implements RequestHandlerInterface
2020
private $pathParams;
2121

2222
/**
23-
* @param callable $handler
23+
* @param callable(ServerRequestInterface, array): ResponseInterface $handler
2424
* @param array $pathParams
2525
*/
2626
public function __construct(callable $handler, array $pathParams = [])

src/Stratigility/Stratigility.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ function process(ServerRequestInterface $request, string $name = DEFAULT_STRATIG
3232
throw new UnexpectedValueException("MiddlewarePipe with name $name not found");
3333
}
3434

35-
return function (callable $handler) use ($pipeline, $request) {
36-
return function (array $pathParams) use ($pipeline, $request, $handler) {
37-
return $pipeline->process($request, new RequestHandlerDecorator($handler, $pathParams));
35+
return
36+
/**
37+
* @param callable(ServerRequestInterface, array): ResponseInterface $handler
38+
* @return Closure
39+
*/
40+
static function (callable $handler) use ($pipeline, $request) {
41+
return static function (array $pathParams) use ($pipeline, $request, $handler) {
42+
return $pipeline->process($request, new RequestHandlerDecorator($handler, $pathParams));
43+
};
3844
};
39-
};
4045
}
4146

4247
/**

src/Swoole/Swoole.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ function bearer(): ?string
432432
* Creates a HTTP server from a server port.
433433
*
434434
* @param Server $server
435-
* @param callable $handler
435+
* @param callable(Request, Response):mixed $handler
436436
* @param int $port
437437
* @param string $host
438438
*

0 commit comments

Comments
 (0)