Skip to content

Commit

Permalink
Use more specific type hints (#200)
Browse files Browse the repository at this point in the history
* Use more specific type hints

* Sync FakeItemsStorage, fix unit tests
  • Loading branch information
arogachev committed Oct 3, 2023
1 parent 8d8d222 commit 8b1ef5d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/ItemsStorageInterface.php
Expand Up @@ -28,10 +28,10 @@ public function getAll(): array;
*
* @param string $name The role or the permission name.
*
* @return Item|null The role or the permission corresponding to the specified name. `null` is returned if no such
* @return Permission|Role|null The role or the permission corresponding to the specified name. `null` is returned if no such
* item.
*/
public function get(string $name): ?Item;
public function get(string $name): Permission|Role|null;

/**
* Whether named role or permission exists.
Expand All @@ -54,17 +54,17 @@ public function roleExists(string $name): bool;
/**
* Adds the role or the permission to RBAC system.
*
* @param Item $item The role or the permission to add.
* @param Permission|Role $item The role or the permission to add.
*/
public function add(Item $item): void;
public function add(Permission|Role $item): void;

/**
* Updates the specified role or permission in the system.
*
* @param string $name The old name of the role or permission.
* @param Item $item Modified role or permission.
* @param Permission|Role $item Modified role or permission.
*/
public function update(string $name, Item $item): void;
public function update(string $name, Permission|Role $item): void;

/**
* Removes a role or permission from the RBAC system.
Expand Down
2 changes: 1 addition & 1 deletion src/Manager.php
Expand Up @@ -308,7 +308,7 @@ private function executeRule(string $user, Item $item, array $params): bool
/**
* @throws ItemAlreadyExistsException
*/
private function addItem(Item $item): void
private function addItem(Permission|Role $item): void
{
if ($this->itemsStorage->exists($item->getName())) {
throw new ItemAlreadyExistsException($item);
Expand Down
6 changes: 3 additions & 3 deletions tests/Support/FakeItemsStorage.php
Expand Up @@ -19,7 +19,7 @@ public function getAll(): array
return $this->items;
}

public function get(string $name): ?Item
public function get(string $name): Permission|Role|null
{
return $this->items[$name] ?? null;
}
Expand All @@ -34,7 +34,7 @@ public function roleExists(string $name): bool
return isset($this->getItemsByType(Item::TYPE_ROLE)[$name]);
}

public function add(Item $item): void
public function add(Permission|Role $item): void
{
$this->items[$item->getName()] = $item;
}
Expand Down Expand Up @@ -164,7 +164,7 @@ public function remove(string $name): void
$this->removeItemByName($name);
}

public function update(string $name, Item $item): void
public function update(string $name, Permission|Role $item): void
{
if ($item->getName() !== $name) {
$this->updateItemName($name, $item);
Expand Down

0 comments on commit 8b1ef5d

Please sign in to comment.