Skip to content

Commit

Permalink
Improve types more
Browse files Browse the repository at this point in the history
  • Loading branch information
arogachev committed Dec 6, 2023
1 parent 184a797 commit 15efe5d
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/ItemsStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ public function getRoles(): array

public function getRolesByNames(array $names): array
{
/** @psalm-var array<string, Role> */
return array_filter(
$this->getAll(),
static fn (Item $item): bool => $item->getType() === Item::TYPE_ROLE && in_array($item->getName(), $names),
static fn (Permission|Role $item): bool => $item instanceof Role && in_array($item->getName(), $names),
);
}

Expand All @@ -114,11 +113,10 @@ public function getPermissions(): array

public function getPermissionsByNames(array $names): array
{
/** @psalm-var array<string, Permission> */
return array_filter(
$this->getAll(),
static function (Item $item) use ($names): bool {
return $item->getType() === Item::TYPE_PERMISSION && in_array($item->getName(), $names);
static function (Permission|Role $item) use ($names): bool {
return $item instanceof Permission && in_array($item->getName(), $names);
},
);
}
Expand Down Expand Up @@ -336,15 +334,13 @@ private function hasItem(string $name): bool
/**
* @psalm-param Item::TYPE_* $type
*
* @return Item[]
* @psalm-return ($type is Item::TYPE_PERMISSION ? array<string, Permission> : array<string, Role>)
*/
private function getItemsByType(string $type): array
{
/** @psalm-var array<string, Permission> | array<string, Role> */
return array_filter(
$this->getAll(),
static fn (Item $item): bool => $item->getType() === $type,
static fn (Permission|Role $item): bool => $item->getType() === $type,
);
}

Expand Down

0 comments on commit 15efe5d

Please sign in to comment.