Skip to content

Commit

Permalink
Upgrade Psalm up to v5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralbot committed Apr 10, 2023
1 parent ccd7828 commit 9d0e190
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -41,7 +41,7 @@
"phpunit/phpunit": "^9.5.20",
"mockery/mockery": "^1.5",
"nyholm/psr7": "^1.5",
"vimeo/psalm": "^4.27"
"vimeo/psalm": "^5.9"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 2 additions & 0 deletions psalm.xml
Expand Up @@ -11,6 +11,8 @@
findUnusedVariablesAndParams="true"
ensureArrayStringOffsetsExist="true"
addParamDefaultToDocblockType="true"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
Expand Down
13 changes: 12 additions & 1 deletion src/GroupRegistry.php
Expand Up @@ -8,6 +8,8 @@

/**
* Manages the presets for various route groups.
*
* @implements \IteratorAggregate<non-empty-string, RouteGroup>
*/
final class GroupRegistry implements \IteratorAggregate
{
Expand All @@ -21,6 +23,9 @@ public function __construct(
) {
}

/**
* @param non-empty-string $name
*/
public function getGroup(string $name): RouteGroup
{
if (!isset($this->groups[$name])) {
Expand All @@ -30,13 +35,19 @@ public function getGroup(string $name): RouteGroup
return $this->groups[$name];
}

/**
* @param non-empty-string $group
*/
public function setDefaultGroup(string $group): self
{
$this->defaultGroup = $group;

return $this;
}

/**
* @return non-empty-string
*/
public function getDefaultGroup(): string
{
return $this->defaultGroup;
Expand All @@ -55,7 +66,7 @@ public function registerRoutes(RouterInterface $router): void
}

/**
* @return \ArrayIterator<array-key, RouteGroup>
* @return \ArrayIterator<non-empty-string, RouteGroup>
*/
public function getIterator(): \Traversable
{
Expand Down
37 changes: 33 additions & 4 deletions src/RouteCollection.php
Expand Up @@ -6,9 +6,12 @@

use Spiral\Router\Loader\Configurator\RouteConfigurator;

/**
* @implements \IteratorAggregate<non-empty-string, RouteConfigurator>
*/
class RouteCollection implements \IteratorAggregate, \Countable
{
/** @var array<string, RouteConfigurator> */
/** @var array<non-empty-string, RouteConfigurator> */
private array $routes = [];

public function __clone()
Expand All @@ -21,7 +24,7 @@ public function __clone()
/**
* Gets the current RouteCollection as an Iterator that includes all routes.
*
* @return \ArrayIterator<string, RouteConfigurator>
* @return \ArrayIterator<non-empty-string, RouteConfigurator>
*/
public function getIterator(): \ArrayIterator
{
Expand All @@ -36,6 +39,13 @@ public function count(): int
return \count($this->routes);
}

/**
* @param non-empty-string $name
*
* @return void
*
* TODO add return type
*/
public function add(string $name, RouteConfigurator $route)
{
$this->routes[$name] = $route;
Expand All @@ -44,7 +54,7 @@ public function add(string $name, RouteConfigurator $route)
/**
* Returns all routes in this collection.
*
* @return array<string, RouteConfigurator>
* @return array<non-empty-string, RouteConfigurator>
*/
public function all(): array
{
Expand All @@ -53,6 +63,8 @@ public function all(): array

/**
* Gets a route by name.
*
* @param non-empty-string $name
*/
public function get(string $name): ?RouteConfigurator
{
Expand All @@ -61,6 +73,8 @@ public function get(string $name): ?RouteConfigurator

/**
* Check a route by name.
*
* @param non-empty-string $name
*/
public function has(string $name): bool
{
Expand All @@ -70,7 +84,11 @@ public function has(string $name): bool
/**
* Removes a route or an array of routes by name from the collection.
*
* @param string|string[] $name The route name or an array of route names
* @param non-empty-string|non-empty-string[] $name The route name or an array of route names
*
* @return void
*
* TODO add return type
*/
public function remove(string|array $name)
{
Expand All @@ -79,6 +97,11 @@ public function remove(string|array $name)
}
}

/**
* @return void
*
* TODO add return type
*/
public function addCollection(self $collection)
{
foreach ($collection->all() as $name => $route) {
Expand All @@ -88,6 +111,12 @@ public function addCollection(self $collection)

/**
* Adds a specific group to a route.
*
* @param non-empty-string $group
*
* @return void
*
* TODO add return type
*/
public function group(string $group)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/VerbsTrait.php
Expand Up @@ -14,7 +14,7 @@ trait VerbsTrait
/**
* Attach specific list of HTTP verbs to the route.
*
* @return RouteInterface|$this
* @return $this
* @throws RouteException
*/
public function withVerbs(string ...$verbs): RouteInterface
Expand Down

0 comments on commit 9d0e190

Please sign in to comment.