Skip to content

Commit

Permalink
Add more strict typing for LocatorInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
lisachenko committed Mar 18, 2024
1 parent 1445fe4 commit 6a8ec25
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
4 changes: 1 addition & 3 deletions src/Locator/CallableLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ public function __construct(callable $callable)
* Returns a path to the file for given class name
*
* @param string $className Name of the class
*
* @return string|false Path to the file with given class or false if not found
*/
public function locateClass(string $className)
public function locateClass(string $className): false|string
{
return call_user_func($this->callable, ltrim($className, '\\'));
}
Expand Down
6 changes: 2 additions & 4 deletions src/Locator/ComposerLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ public function __construct(ClassLoader $composerLoader = null)
* Returns a path to the file for given class name
*
* @param string $className Name of the class
*
* @return string|false Path to the file with given class or false if not found
*/
public function locateClass(string $className)
**/
public function locateClass(string $className): false|string
{
$filePath = $this->loader->findFile(ltrim($className, '\\'));
if (!empty($filePath)) {
Expand Down
4 changes: 1 addition & 3 deletions src/LocatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ interface LocatorInterface
* Returns a path to the file for given class name
*
* @param string $className Name of the class (with or without leading '\' FQCN)
*
* @return string|false Path to the file with given class or false if not found
*/
public function locateClass(string $className);
public function locateClass(string $className): false|string;
}
2 changes: 1 addition & 1 deletion tests/Stub/Issue44/Locator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Locator implements LocatorInterface
/**
* @inheritdoc
*/
public function locateClass(string $className)
public function locateClass(string $className): false|string
{
if (ltrim($className, '\\') === ClassWithNamespace::class) {
return __DIR__ . '/ClassWithNamespace.php';
Expand Down

0 comments on commit 6a8ec25

Please sign in to comment.