Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
*/
abstract class Item
{
public const TYPE_ROLE = 'role';
public const TYPE_PERMISSION = 'permission';
public const TYPE_ROLE = 1;
public const TYPE_PERMISSION = 2;

/**
* @var string The item description.
Expand Down Expand Up @@ -41,9 +41,10 @@ final public function __construct(private string $name)
}

/**
* @return string Type of the item.
* @return int Type of the item.
* @psalm-return Item::TYPE_*
*/
abstract public function getType(): string;
abstract public function getType(): int;

/**
* @return string Authorization item name.
Expand Down Expand Up @@ -139,7 +140,7 @@ final public function hasUpdatedAt(): bool
* name: string,
* description: string,
* rule_name: string|null,
* type: string,
* type: Item::TYPE_*,
* updated_at: int|null,
* created_at: int|null,
* }
Expand Down
2 changes: 1 addition & 1 deletion src/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

final class Permission extends Item
{
public function getType(): string
public function getType(): int
{
return self::TYPE_PERMISSION;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

final class Role extends Item
{
public function getType(): string
public function getType(): int
{
return self::TYPE_ROLE;
}
Expand Down
4 changes: 2 additions & 2 deletions src/SimpleItemsStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private function updateItemName(string $name, Item $item): void
*
* @psalm-return ($type is Item::TYPE_PERMISSION ? array<string, Permission> : array<string, Role>)
*/
private function getItemsByType(string $type): array
private function getItemsByType(int $type): array
{
return array_filter(
$this->getAll(),
Expand All @@ -250,7 +250,7 @@ private function getItemsByType(string $type): array
/**
* @psalm-param Item::TYPE_* $type
*/
private function removeItemsByType(string $type): void
private function removeItemsByType(int $type): void
{
foreach ($this->getItemsByType($type) as $item) {
$this->remove($item->getName());
Expand Down
5 changes: 3 additions & 2 deletions tests/Common/ManagerLogicTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Yiisoft\Rbac\Exception\ItemAlreadyExistsException;
use Yiisoft\Rbac\Exception\RuleInterfaceNotImplementedException;
use Yiisoft\Rbac\Exception\RuleNotFoundException;
use Yiisoft\Rbac\Item;
use Yiisoft\Rbac\Permission;
use Yiisoft\Rbac\Role;
use Yiisoft\Rbac\RuleInterface;
Expand Down Expand Up @@ -727,7 +728,7 @@ public function testAddRole(): void
'name' => 'new role',
'description' => 'new role description',
'rule_name' => TrueRule::class,
'type' => 'role',
'type' => Item::TYPE_ROLE,
'updated_at' => 1_642_026_148,
'created_at' => 1_642_026_147,
],
Expand Down Expand Up @@ -792,7 +793,7 @@ public function testAddPermission(): void
'name' => 'edit post',
'description' => 'edit a post',
'rule_name' => null,
'type' => 'permission',
'type' => Item::TYPE_PERMISSION,
'updated_at' => 1_642_026_148,
'created_at' => 1_642_026_147,
],
Expand Down