Skip to content

Commit

Permalink
Typo fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
akrabat committed Jun 14, 2024
1 parent 8b1797c commit 0728dee
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions _posts/2024-06-13-slim-4.14.0-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ can be seen [here](https://github.com/slimphp/Slim/releases/tag/4.14.0).

This release introduces of [template generic docblocks](https://phpstan.org/blog/generics-in-php-using-phpdocs) into Slim.

As <tt>Slim\App<tt> has a <tt>getContainer(): ?ContainerInterface</tt> method, the generics docblock enables you to specify what type is actually returned when this method is called.
As <tt>Slim\App</tt> has a <tt>getContainer(): ?ContainerInterface</tt> method, the generics docblock enables you to specify what type is actually returned when this method is called.
i.e. consider that you are using [PHP-DI](https://php-di.org) and have this code:

```
$container = $this->app->getContainer();
$entries = $container->getKnownEntryNames();
```

[PHPStan](https://phpstan.org/) has no way of knowing that <tt>$container</tt> is an instance of<tt>DI\Container</tt> which has a <tt>getKnownEntryNames()</tt> method and so will complain.
[PHPStan](https://phpstan.org/) has no way of knowing that <tt>$container</tt> is an instance of <tt>DI\Container</tt> which has a <tt>getKnownEntryNames()</tt> method and so will complain.

To inform PHPStan that we create <tt>Slim\App</tt> with PHP-DI, we change: <tt>/** @var \Slim\App $app */</tt> to <tt>/** @var \Slim\App<DI\Container> $app */</tt> and now PHPStan knows that <tt>getKnownEntryNames()</tt> is a valid method call on <tt>$container</tt>.
To inform PHPStan that we created <tt>Slim\App</tt> with PHP-DI, we change: <tt>/** @var \Slim\App $app */</tt> to <tt>/** @var \Slim\App<DI\Container> $app */</tt> and now PHPStan knows that <tt>getKnownEntryNames()</tt> is a valid method call on <tt>$container</tt>.


### Update your type hints

For your codebase, if you type hint <tt>Slim\App</tt> instance variable using <tt>/** @var \Slim\App $app */</tt>, then you will need to change it to either:
For your codebase, if you type hint <tt>Slim\App</tt> instance variables using <tt>/** @var \Slim\App $app */</tt>, then you will need to change it to either:

* <tt>/** @var \Slim\App<null> $app */</tt> if you are not using a DI container, or
* <tt>/** @var \Slim\App<\Psr\Container\ContainerInterface> $app */</tt> if you are.
Expand Down

0 comments on commit 0728dee

Please sign in to comment.