@@ -52,12 +52,10 @@ class Permission implements Authorizator
5252 /**
5353 * Adds a Role to the list. The most recently added parent
5454 * takes precedence over parents that were previously added.
55- * @param string|array $parents
5655 * @throws Nette\InvalidArgumentException
5756 * @throws Nette\InvalidStateException
58- * @return static
5957 */
60- public function addRole (string $ role , $ parents = null )
58+ public function addRole (string $ role , string | array | null $ parents = null ): static
6159 {
6260 $ this ->checkRole ($ role , false );
6361 if (isset ($ this ->roles [$ role ])) {
@@ -161,9 +159,8 @@ public function roleInheritsFrom(string $role, string $inherit, bool $onlyParent
161159 * Removes the Role from the list.
162160 *
163161 * @throws Nette\InvalidStateException
164- * @return static
165162 */
166- public function removeRole (string $ role )
163+ public function removeRole (string $ role ): static
167164 {
168165 $ this ->checkRole ($ role );
169166
@@ -199,10 +196,8 @@ public function removeRole(string $role)
199196
200197 /**
201198 * Removes all Roles from the list.
202- *
203- * @return static
204199 */
205- public function removeAllRoles ()
200+ public function removeAllRoles (): static
206201 {
207202 $ this ->roles = [];
208203
@@ -228,9 +223,8 @@ public function removeAllRoles()
228223 *
229224 * @throws Nette\InvalidArgumentException
230225 * @throws Nette\InvalidStateException
231- * @return static
232226 */
233- public function addResource (string $ resource , ?string $ parent = null )
227+ public function addResource (string $ resource , ?string $ parent = null ): static
234228 {
235229 $ this ->checkResource ($ resource , false );
236230
@@ -324,9 +318,8 @@ public function resourceInheritsFrom(string $resource, string $inherit, bool $on
324318 * Removes a Resource and all of its children.
325319 *
326320 * @throws Nette\InvalidStateException
327- * @return static
328321 */
329- public function removeResource (string $ resource )
322+ public function removeResource (string $ resource ): static
330323 {
331324 $ this ->checkResource ($ resource );
332325
@@ -356,9 +349,8 @@ public function removeResource(string $resource)
356349
357350 /**
358351 * Removes all Resources.
359- * @return static
360352 */
361- public function removeAllResources ()
353+ public function removeAllResources (): static
362354 {
363355 foreach ($ this ->resources as $ resource => $ foo ) {
364356 foreach ($ this ->rules ['byResource ' ] as $ resourceCurrent => $ rules ) {
@@ -383,14 +375,14 @@ public function removeAllResources()
383375 * @param string|string[]|null $roles
384376 * @param string|string[]|null $resources
385377 * @param string|string[]|null $privileges
386- * @return static
387378 */
388379 public function allow (
389380 $ roles = self ::ALL ,
390381 $ resources = self ::ALL ,
391382 $ privileges = self ::ALL ,
392383 ?callable $ assertion = null ,
393- ) {
384+ ): static
385+ {
394386 $ this ->setRule (true , self ::ALLOW , $ roles , $ resources , $ privileges , $ assertion );
395387 return $ this ;
396388 }
@@ -403,14 +395,14 @@ public function allow(
403395 * @param string|string[]|null $roles
404396 * @param string|string[]|null $resources
405397 * @param string|string[]|null $privileges
406- * @return static
407398 */
408399 public function deny (
409400 $ roles = self ::ALL ,
410401 $ resources = self ::ALL ,
411402 $ privileges = self ::ALL ,
412403 ?callable $ assertion = null ,
413- ) {
404+ ): static
405+ {
414406 $ this ->setRule (true , self ::DENY , $ roles , $ resources , $ privileges , $ assertion );
415407 return $ this ;
416408 }
@@ -422,9 +414,8 @@ public function deny(
422414 * @param string|string[]|null $roles
423415 * @param string|string[]|null $resources
424416 * @param string|string[]|null $privileges
425- * @return static
426417 */
427- public function removeAllow ($ roles = self ::ALL , $ resources = self ::ALL , $ privileges = self ::ALL )
418+ public function removeAllow ($ roles = self ::ALL , $ resources = self ::ALL , $ privileges = self ::ALL ): static
428419 {
429420 $ this ->setRule (false , self ::ALLOW , $ roles , $ resources , $ privileges );
430421 return $ this ;
@@ -437,9 +428,8 @@ public function removeAllow($roles = self::ALL, $resources = self::ALL, $privile
437428 * @param string|string[]|null $roles
438429 * @param string|string[]|null $resources
439430 * @param string|string[]|null $privileges
440- * @return static
441431 */
442- public function removeDeny ($ roles = self ::ALL , $ resources = self ::ALL , $ privileges = self ::ALL )
432+ public function removeDeny ($ roles = self ::ALL , $ resources = self ::ALL , $ privileges = self ::ALL ): static
443433 {
444434 $ this ->setRule (false , self ::DENY , $ roles , $ resources , $ privileges );
445435 return $ this ;
@@ -452,9 +442,15 @@ public function removeDeny($roles = self::ALL, $resources = self::ALL, $privileg
452442 * @param string|string[]|null $resources
453443 * @param string|string[]|null $privileges
454444 * @throws Nette\InvalidStateException
455- * @return static
456445 */
457- protected function setRule (bool $ toAdd , bool $ type , $ roles , $ resources , $ privileges , ?callable $ assertion = null )
446+ protected function setRule (
447+ bool $ toAdd ,
448+ bool $ type ,
449+ $ roles ,
450+ $ resources ,
451+ $ privileges ,
452+ ?callable $ assertion = null ,
453+ ): static
458454 {
459455 // ensure that all specified Roles exist; normalize input to array of Roles or null
460456 if ($ roles === self ::ALL ) {
@@ -564,12 +560,13 @@ protected function setRule(bool $toAdd, bool $type, $roles, $resources, $privile
564560 * and its respective parents are checked similarly before the lower-priority parents of
565561 * the Role are checked.
566562 *
567- * @param string|Role|null $role
568- * @param string|Nette\Security\Resource|null $resource
569- * @param string|null $privilege
570563 * @throws Nette\InvalidStateException
571564 */
572- public function isAllowed ($ role = self ::ALL , $ resource = self ::ALL , $ privilege = self ::ALL ): bool
565+ public function isAllowed (
566+ string |Role |null $ role = self ::ALL ,
567+ string |Nette \Security \Resource |null $ resource = self ::ALL ,
568+ ?string $ privilege = self ::ALL ,
569+ ): bool
573570 {
574571 $ this ->queriedRole = $ role ;
575572 if ($ role !== self ::ALL ) {
@@ -626,19 +623,17 @@ public function isAllowed($role = self::ALL, $resource = self::ALL, $privilege =
626623
627624 /**
628625 * Returns real currently queried Role. Use by assertion.
629- * @return mixed
630626 */
631- public function getQueriedRole ()
627+ public function getQueriedRole (): mixed
632628 {
633629 return $ this ->queriedRole ;
634630 }
635631
636632
637633 /**
638634 * Returns real currently queried Resource. Use by assertion.
639- * @return mixed
640635 */
641- public function getQueriedResource ()
636+ public function getQueriedResource (): mixed
642637 {
643638 return $ this ->queriedResource ;
644639 }
@@ -653,7 +648,7 @@ public function getQueriedResource()
653648 * @param bool $all (true) or one?
654649 * @return mixed null if no applicable rule is found, otherwise returns ALLOW or DENY
655650 */
656- private function searchRolePrivileges (bool $ all , $ role , $ resource , $ privilege )
651+ private function searchRolePrivileges (bool $ all , $ role , $ resource , $ privilege ): mixed
657652 {
658653 $ dfs = [
659654 'visited ' => [],
@@ -698,12 +693,9 @@ private function searchRolePrivileges(bool $all, $role, $resource, $privilege)
698693
699694 /**
700695 * Returns the rule type associated with the specified Resource, Role, and privilege.
701- * @param string|null $resource
702- * @param string|null $role
703- * @param string|null $privilege
704696 * @return bool|null null if a rule does not exist or assertion fails, otherwise returns ALLOW or DENY
705697 */
706- private function getRuleType ($ resource , $ role , $ privilege ): ?bool
698+ private function getRuleType (? string $ resource , ? string $ role , ? string $ privilege ): ?bool
707699 {
708700 if (!$ rules = $ this ->getRules ($ resource , $ role )) {
709701 return null ;
@@ -740,10 +732,8 @@ private function getRuleType($resource, $role, $privilege): ?bool
740732 /**
741733 * Returns the rules associated with a Resource and a Role, or null if no such rules exist.
742734 * If the $create parameter is true, then a rule set is first created and then returned to the caller.
743- * @param string|null $resource
744- * @param string|null $role
745735 */
746- private function &getRules ($ resource , $ role , bool $ create = false ): ?array
736+ private function &getRules (? string $ resource , ? string $ role , bool $ create = false ): ?array
747737 {
748738 $ null = null ;
749739 if ($ resource === self ::ALL ) {
0 commit comments