Skip to content

Commit

Permalink
minor #53670 [Config] Provide more precise phpdoc for `FileLocatorInt…
Browse files Browse the repository at this point in the history
…erface::locate()` (VincentLanglet)

This PR was merged into the 6.4 branch.

Discussion
----------

[Config] Provide more precise phpdoc for `FileLocatorInterface::locate()`

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | ?
| New feature?  | ?
| Deprecations? | no
| Issues        | Fix #...
| License       | MIT

When working with psalm/phpstan, they believe `$locator->locate('...');` returns possibly an array which is not true.
This can be defined with ``@psalm`-return` annotation that Symfony started to integrate in the code base.

Commits
-------

b2afd32 Provide more precise phpdoc for FileLocatorInterface::locate
  • Loading branch information
nicolas-grekas committed Jan 30, 2024
2 parents 89d3197 + b2afd32 commit cb68bf3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Symfony/Component/Config/FileLocator.php
Expand Up @@ -31,7 +31,9 @@ public function __construct(string|array $paths = [])
}

/**
* @return string|array
* @return string|string[]
*
* @psalm-return ($first is true ? string : string[])
*/
public function locate(string $name, ?string $currentPath = null, bool $first = true)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/Config/FileLocatorInterface.php
Expand Up @@ -25,10 +25,12 @@ interface FileLocatorInterface
* @param string|null $currentPath The current path
* @param bool $first Whether to return the first occurrence or an array of filenames
*
* @return string|array The full path to the file or an array of file paths
* @return string|string[] The full path to the file or an array of file paths
*
* @throws \InvalidArgumentException If $name is empty
* @throws FileLocatorFileNotFoundException If a file is not found
*
* @psalm-return ($first is true ? string : string[])
*/
public function locate(string $name, ?string $currentPath = null, bool $first = true);
}

0 comments on commit cb68bf3

Please sign in to comment.