Skip to content

Commit

Permalink
Improve type hinting to level 9 in phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Nov 24, 2023
1 parent 2fb5db4 commit c620733
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
10 changes: 8 additions & 2 deletions src/Application/FinalCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ public function __invoke(ServerRequestInterface $request)
$reflector = new \ReflectionFunction($closure);
}

$function[1] = $this->container->arguments($reflector, $function[1]);
/** @var callable */
$callable = $function[0];

$this->function = call_user_func_array($function[0], $function[1]);
/** @var array<string, mixed> */
$parameters = $function[1];

$parameters = $this->container->arguments($reflector, $parameters);

$this->function = call_user_func_array($callable, $parameters);

return $this->finalize($this->function);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/HttpIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function define(ContainerInterface $container, Configuration $config)
/** @var array<string, string> */
$query = $globals[2];

/** @var array<string, array<string, string>> */
/** @var array<string, array<string, string[]>> */
$files = $globals[3];

/** @var array<string, mixed>|null|object */
Expand Down
2 changes: 1 addition & 1 deletion src/Http/ServerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ServerRequest extends Request implements ServerRequestInterface
* @param array<string, string> $server
* @param array<string, string> $cookies
* @param array<string, string> $query
* @param array<string, array<string, string>> $uploaded
* @param array<string, array<string, string[]>> $uploaded
* @param array<string, mixed>|null|object $data
* @param array<string, string> $attributes
* @param \Psr\Http\Message\UriInterface|null $uri
Expand Down
26 changes: 16 additions & 10 deletions src/Http/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,25 @@ public function moveTo($target)
/**
* Parses the $_FILES into multiple \File instances.
*
* @param array<string, mixed> $uploaded
* @param array<string, array<string, string[]>> $uploaded
* @return array<string, \Psr\Http\Message\UploadedFileInterface[]>
*/
public static function normalize(array $uploaded)
{
$diversed = self::diverse($uploaded);

/** @var array<string, \Psr\Http\Message\UploadedFileInterface[]> */
$files = array();

foreach (self::diverse($uploaded) as $name => $file)
foreach ($diversed as $name => $file)
{
list($files[$name], $items) = array($file, array());
$items = array();

if (! isset($file['name'])) continue;

foreach ($file['name'] as $key => $value)
{
$instance = self::create($file, $key);

array_push($items, $instance);
$items[] = self::create($file, $key);
}

$files[$name] = (array) $items;
Expand All @@ -176,20 +177,25 @@ public static function normalize(array $uploaded)
/**
* Creates a new UploadedFile instance.
*
* @param array<string, mixed> $file
* @param integer $key
* @param array<string, array<int, string|integer>> $file
* @param integer $key
* @return \Psr\Http\Message\UploadedFileInterface
*/
protected static function create(array $file, $key)
{
/** @var string */
$tmp = $file['tmp_name'][$key];

/** @var integer */
$size = $file['size'][$key];

/** @var integer */
$error = $file['error'][$key];

/** @var string */
$original = $file['name'][$key];

/** @var string */
$type = $file['type'][$key];

return new UploadedFile($tmp, $size, $error, $original, $type);
Expand All @@ -198,8 +204,8 @@ protected static function create(array $file, $key)
/**
* Diverse the $_FILES into a consistent result.
*
* @param array<string, mixed> $uploaded
* @return array<string, mixed>
* @param array<string, array<string, string[]>> $uploaded
* @return array<string, array<string, string[]>>
*/
protected static function diverse(array $uploaded)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Routing/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ protected function parse($httpMethod, $uri, $route)

/**
* Retrieved the specified route from the result.
*
*
* @param array<int, array<int, \Interop\Http\ServerMiddleware\MiddlewareInterface[]|string[]|string>|null> $routes
* @param string $uri
* @return array<int, \Interop\Http\ServerMiddleware\MiddlewareInterface[]|string[]|string>
*
*
* @throws \UnexpectedValueException
*/
protected function retrieve(array $routes, $uri)
Expand Down

0 comments on commit c620733

Please sign in to comment.