Fix #20591: Add PHPStan/Psalm annotations for yii\rbac\BaseManager::getItems()

This commit is contained in:
Maksim Spirkov
2025-10-13 10:04:49 +03:00
committed by GitHub
parent 4621557d92
commit df400b6a19
2 changed files with 19 additions and 2 deletions

View File

@@ -44,6 +44,12 @@ abstract class BaseManager extends Component implements ManagerInterface
* Returns the items of the specified type.
* @param int $type the auth item type (either [[Item::TYPE_ROLE]] or [[Item::TYPE_PERMISSION]]
* @return Item[] the auth items of the specified type.
*
* @phpstan-param Item::TYPE_ROLE|Item::TYPE_PERMISSION $type
* @psalm-param Item::TYPE_ROLE|Item::TYPE_PERMISSION $type
*
* @phpstan-return ($type is Item::TYPE_ROLE ? Role[] : Permission[])
* @psalm-return ($type is Item::TYPE_ROLE ? Role[] : Permission[])
*/
abstract protected function getItems($type);
@@ -177,7 +183,12 @@ abstract class BaseManager extends Component implements ManagerInterface
public function getRole($name)
{
$item = $this->getItem($name);
return $item instanceof Item && $item->type == Item::TYPE_ROLE ? $item : null;
if ($item instanceof Item && $item->type == Item::TYPE_ROLE) {
/** @var Role $item */
return $item;
}
return null;
}
/**
@@ -186,7 +197,12 @@ abstract class BaseManager extends Component implements ManagerInterface
public function getPermission($name)
{
$item = $this->getItem($name);
return $item instanceof Item && $item->type == Item::TYPE_PERMISSION ? $item : null;
if ($item instanceof Item && $item->type == Item::TYPE_PERMISSION) {
/** @var Permission $item */
return $item;
}
return null;
}
/**