@@ -49,12 +49,10 @@ class Permission implements Authorizator
4949 /**
5050 * Adds a Role to the list. The most recently added parent
5151 * takes precedence over parents that were previously added.
52- * @param string|array $parents
5352 * @throws Nette\InvalidArgumentException
5453 * @throws Nette\InvalidStateException
55- * @return static
5654 */
57- public function addRole (string $ role , $ parents = null )
55+ public function addRole (string $ role , string | array $ parents = null ): static
5856 {
5957 $ this ->checkRole ($ role , exists: false );
6058 if (isset ($ this ->roles [$ role ])) {
@@ -158,9 +156,8 @@ public function roleInheritsFrom(string $role, string $inherit, bool $onlyParent
158156 * Removes the Role from the list.
159157 *
160158 * @throws Nette\InvalidStateException
161- * @return static
162159 */
163- public function removeRole (string $ role )
160+ public function removeRole (string $ role ): static
164161 {
165162 $ this ->checkRole ($ role );
166163
@@ -196,10 +193,8 @@ public function removeRole(string $role)
196193
197194 /**
198195 * Removes all Roles from the list.
199- *
200- * @return static
201196 */
202- public function removeAllRoles ()
197+ public function removeAllRoles (): static
203198 {
204199 $ this ->roles = [];
205200
@@ -225,9 +220,8 @@ public function removeAllRoles()
225220 *
226221 * @throws Nette\InvalidArgumentException
227222 * @throws Nette\InvalidStateException
228- * @return static
229223 */
230- public function addResource (string $ resource , ?string $ parent = null )
224+ public function addResource (string $ resource , ?string $ parent = null ): static
231225 {
232226 $ this ->checkResource ($ resource , exists: false );
233227
@@ -321,9 +315,8 @@ public function resourceInheritsFrom(string $resource, string $inherit, bool $on
321315 * Removes a Resource and all of its children.
322316 *
323317 * @throws Nette\InvalidStateException
324- * @return static
325318 */
326- public function removeResource (string $ resource )
319+ public function removeResource (string $ resource ): static
327320 {
328321 $ this ->checkResource ($ resource );
329322
@@ -353,9 +346,8 @@ public function removeResource(string $resource)
353346
354347 /**
355348 * Removes all Resources.
356- * @return static
357349 */
358- public function removeAllResources ()
350+ public function removeAllResources (): static
359351 {
360352 foreach ($ this ->resources as $ resource => $ foo ) {
361353 foreach ($ this ->rules ['byResource ' ] as $ resourceCurrent => $ rules ) {
@@ -376,18 +368,14 @@ public function removeAllResources()
376368 /**
377369 * Allows one or more Roles access to [certain $privileges upon] the specified Resource(s).
378370 * If $assertion is provided, then it must return true in order for rule to apply.
379- *
380- * @param string|string[]|null $roles
381- * @param string|string[]|null $resources
382- * @param string|string[]|null $privileges
383- * @return static
384371 */
385372 public function allow (
386- $ roles = self ::All,
387- $ resources = self ::All,
388- $ privileges = self ::All,
373+ string | array | null $ roles = self ::All,
374+ string | array | null $ resources = self ::All,
375+ string | array | null $ privileges = self ::All,
389376 ?callable $ assertion = null ,
390- ) {
377+ ): static
378+ {
391379 $ this ->setRule (true , self ::Allow, $ roles , $ resources , $ privileges , $ assertion );
392380 return $ this ;
393381 }
@@ -396,32 +384,27 @@ public function allow(
396384 /**
397385 * Denies one or more Roles access to [certain $privileges upon] the specified Resource(s).
398386 * If $assertion is provided, then it must return true in order for rule to apply.
399- *
400- * @param string|string[]|null $roles
401- * @param string|string[]|null $resources
402- * @param string|string[]|null $privileges
403- * @return static
404387 */
405388 public function deny (
406- $ roles = self ::All,
407- $ resources = self ::All,
408- $ privileges = self ::All,
389+ string | array | null $ roles = self ::All,
390+ string | array | null $ resources = self ::All,
391+ string | array | null $ privileges = self ::All,
409392 ?callable $ assertion = null ,
410- ) {
393+ ): static
394+ {
411395 $ this ->setRule (true , self ::Deny, $ roles , $ resources , $ privileges , $ assertion );
412396 return $ this ;
413397 }
414398
415399
416400 /**
417401 * Removes "allow" permissions from the list in the context of the given Roles, Resources, and privileges.
418- *
419- * @param string|string[]|null $roles
420- * @param string|string[]|null $resources
421- * @param string|string[]|null $privileges
422- * @return static
423402 */
424- public function removeAllow ($ roles = self ::All, $ resources = self ::All, $ privileges = self ::All)
403+ public function removeAllow (
404+ string |array |null $ roles = self ::All,
405+ string |array |null $ resources = self ::All,
406+ string |array |null $ privileges = self ::All,
407+ ): static
425408 {
426409 $ this ->setRule (false , self ::Allow, $ roles , $ resources , $ privileges );
427410 return $ this ;
@@ -430,13 +413,12 @@ public function removeAllow($roles = self::All, $resources = self::All, $privile
430413
431414 /**
432415 * Removes "deny" restrictions from the list in the context of the given Roles, Resources, and privileges.
433- *
434- * @param string|string[]|null $roles
435- * @param string|string[]|null $resources
436- * @param string|string[]|null $privileges
437- * @return static
438416 */
439- public function removeDeny ($ roles = self ::All, $ resources = self ::All, $ privileges = self ::All)
417+ public function removeDeny (
418+ string |array |null $ roles = self ::All,
419+ string |array |null $ resources = self ::All,
420+ string |array |null $ privileges = self ::All,
421+ ): static
440422 {
441423 $ this ->setRule (false , self ::Deny, $ roles , $ resources , $ privileges );
442424 return $ this ;
@@ -445,13 +427,16 @@ public function removeDeny($roles = self::All, $resources = self::All, $privileg
445427
446428 /**
447429 * Performs operations on Access Control List rules.
448- * @param string|string[]|null $roles
449- * @param string|string[]|null $resources
450- * @param string|string[]|null $privileges
451430 * @throws Nette\InvalidStateException
452- * @return static
453431 */
454- protected function setRule (bool $ toAdd , bool $ type , $ roles , $ resources , $ privileges , ?callable $ assertion = null )
432+ protected function setRule (
433+ bool $ toAdd ,
434+ bool $ type ,
435+ string |array |null $ roles ,
436+ string |array |null $ resources ,
437+ string |array |null $ privileges ,
438+ ?callable $ assertion = null ,
439+ ): void
455440 {
456441 // ensure that all specified Roles exist; normalize input to array of Roles or null
457442 if ($ roles === self ::All) {
@@ -545,8 +530,6 @@ protected function setRule(bool $toAdd, bool $type, $roles, $resources, $privile
545530 }
546531 }
547532 }
548-
549- return $ this ;
550533 }
551534
552535
@@ -561,12 +544,13 @@ protected function setRule(bool $toAdd, bool $type, $roles, $resources, $privile
561544 * and its respective parents are checked similarly before the lower-priority parents of
562545 * the Role are checked.
563546 *
564- * @param string|Role|null $role
565- * @param string|Nette\Security\Resource|null $resource
566- * @param string|null $privilege
567547 * @throws Nette\InvalidStateException
568548 */
569- public function isAllowed ($ role = self ::All, $ resource = self ::All, $ privilege = self ::All): bool
549+ public function isAllowed (
550+ string |Role |null $ role = self ::All,
551+ string |Resource |null $ resource = self ::All,
552+ string |null $ privilege = self ::All,
553+ ): bool
570554 {
571555 $ this ->queriedRole = $ role ;
572556 if ($ role !== self ::All) {
@@ -623,19 +607,17 @@ public function isAllowed($role = self::All, $resource = self::All, $privilege =
623607
624608 /**
625609 * Returns real currently queried Role. Use by assertion.
626- * @return mixed
627610 */
628- public function getQueriedRole ()
611+ public function getQueriedRole (): string | Role | null
629612 {
630613 return $ this ->queriedRole ;
631614 }
632615
633616
634617 /**
635618 * Returns real currently queried Resource. Use by assertion.
636- * @return mixed
637619 */
638- public function getQueriedResource ()
620+ public function getQueriedResource (): string | Resource | null
639621 {
640622 return $ this ->queriedResource ;
641623 }
@@ -648,9 +630,8 @@ public function getQueriedResource()
648630 * Performs a depth-first search of the Role DAG, starting at $role, in order to find a rule
649631 * allowing/denying $role access to a/all $privilege upon $resource.
650632 * @param bool $all (true) or one?
651- * @return mixed null if no applicable rule is found, otherwise returns ALLOW or DENY
652633 */
653- private function searchRolePrivileges (bool $ all , $ role , $ resource , $ privilege )
634+ private function searchRolePrivileges (bool $ all , ? string $ role , ? string $ resource , ? string $ privilege ): ? bool
654635 {
655636 $ dfs = [
656637 'visited ' => [],
@@ -695,12 +676,8 @@ private function searchRolePrivileges(bool $all, $role, $resource, $privilege)
695676
696677 /**
697678 * Returns the rule type associated with the specified Resource, Role, and privilege.
698- * @param string|null $resource
699- * @param string|null $role
700- * @param string|null $privilege
701- * @return bool|null null if a rule does not exist or assertion fails, otherwise returns ALLOW or DENY
702679 */
703- private function getRuleType ($ resource , $ role , $ privilege ): ?bool
680+ private function getRuleType (? string $ resource , ? string $ role , ? string $ privilege ): ?bool
704681 {
705682 if (!$ rules = $ this ->getRules ($ resource , $ role )) {
706683 return null ;
@@ -737,10 +714,8 @@ private function getRuleType($resource, $role, $privilege): ?bool
737714 /**
738715 * Returns the rules associated with a Resource and a Role, or null if no such rules exist.
739716 * If the $create parameter is true, then a rule set is first created and then returned to the caller.
740- * @param string|null $resource
741- * @param string|null $role
742717 */
743- private function &getRules ($ resource , $ role , bool $ create = false ): ?array
718+ private function &getRules (? string $ resource , ? string $ role , bool $ create = false ): ?array
744719 {
745720 $ null = null ;
746721 if ($ resource === self ::All) {
0 commit comments